Reputation: 15
Modify.xhtml
<table border="0" align="left" cellpadding="10" cellspacing="0">
<tr>
<td>通訊地址 : </td>
<td><p:selectOneMenu value="#{modify.comAddressContry}" style="width: 120px">
<f:selectItem itemLabel="--選擇城市--" itemValue="--選擇城市--"/>
<f:selectItems value="#{modify.tw.country_map}"/>
<p:ajax update="district_change_com" event="change" listener="#{modify.com_country_change()}"/>
</p:selectOneMenu>
</td>
<td><p:selectOneMenu id="district_change_com" value="#{modify.comAddressDistrict}" style="width: 120px">
<f:selectItem itemLabel="--選擇地區--" itemValue="--選擇地區--" />
<f:selectItems value="#{modify.tw.district_map}"/>
<p:ajax update="com_all" listener="#{modify.com_zipcode_change()}"/>
</p:selectOneMenu>
</td>
<td><p:inputText id="com_all" value="#{modify.comAddressAll}" style="width: 300px"/></td>
<td>通訊地電話 : </td>
<td><p:inputText value="#{modify.houseAddressTel}" maxlength="11" /></td>
</tr>
<tr>
<td>戶籍地址 :</td>
<td><p:selectOneMenu value="#{modify.houseAddressContry}" style="width: 120px">
<f:selectItem itemLabel="--選擇城市--" itemValue="--選擇城市--"/>
<f:selectItems value="#{modify.tw.country_map}"/>
<p:ajax update="district_change" event="change" listener="#{modify.country_change()}"/>
</p:selectOneMenu>
</td>
<td><p:selectOneMenu id="district_change" value="#{modify.houseAddressDistrict}" style="width: 120px">
<f:selectItem itemLabel="--選擇地區--" itemValue="--選擇地區--" />
<f:selectItems value="#{modify.tw.district_map}"/>
<p:ajax update="house_all" listener="#{modify.zipcode_change()}"/>
</p:selectOneMenu>
</td>
<td><p:inputText id="house_all" value="#{modify.houseAddressAll}" style="width: 300px"/></td>
<td>戶籍地電話 : </td>
<td><p:inputText value="#{modify.houseAddressTel}" maxlength="11" /></td>
</tr>
</table>
I am trying for double combo select function in PrimeFaces. It works well when I use it once but when I use it twice in the same page(in the same form) the page show validation error when I submit the chosen data. Have any ideas for this problem?
Upvotes: 1
Views: 800
Reputation: 1108802
That can happen if the bean is request scoped and thus recreated on every single HTTP request (note that every ajax request also counts as a separate HTTP request). On every submit, JSF will validate the submitted dropdown value against the list of available items. However, if the bean is request scoped, this list will be reinitialized to default everytime. So if the default initialized list of the cascaded dropdown list does not represent the right list as it was at the moment the user submitted the form, then you will get a "Validation Error: Value is not valid".
Placing the bean in the view scope, so that it lives as long as you're interacting with the same view, also by ajax requests, should solve the problem.
@ManagedBean
@ViewScoped
public class Modify {
// ...
}
Upvotes: 1