p:pickList验证失败后无法填充数据

p:pickList验证失败后无法填充数据

问题描述:
在一个dialog里有input和pickList;input里填入非法数据后,提交表单,验证失败;立刻关闭dialog,重新打开它,发现pickList无法填充数据。

同样问题已经出现在 stackoverflow, 目前已在官方论坛提问解决办法还未得到有效回答。

URL: here

下面是我做出的解决办法,虽然有点丑陋:
This is an old question, but I also encountered this issue recently, and now being helpless. Let's see the p:pickList:

<td>
    <p:pickList id="customersList" iconOnly="true"
                value="#{addEditUserController.customersList}" var="customer"
                itemValue="#{customer.value}" itemLabel="#{customer.label}"/>
</td>

We know the [var="customer"] is an iterator, but when validation error happens, this var is assigned to String type, it's odd. When you close this popup then re-populate it again, you will get an error, messages like this: no property label(value) on type of String... the customer var now is a String, so it has no value nor label property.

For now, I use a tricky way, it won't work out always, it depends on your code: Assume that the value and label are unique, set customersList type of List String, customersList binds the label, find the value of the label when submit at the backend; Why this way can avoid re-populate exception, that's because the iterator is always type of String, no matter validation error occurs or not.

Hope this can help the need.

你可能感兴趣的:(validation,Fetching,p:pickList)