私はカントリークラスを持っています:
public class Country{
private Long id;
private String name;
}
および2つのCountryフィールドを持つpersonクラス
public class Person{
private Country nationality;
private Country nationality2;
}
現在JSFでは<f:selectItems>
、次のように国籍を選択するために国のリストを返すために使用します。
<h:form id="form1">
<h:selectOneMenu value="#{mybean.person.nationality.id}">
<f:selectItems value="#{mybean.countryList}" var="var" itemValue="#{var.id}"/>
</h:selectOneMenu>
<h:selectOneMenu value="#{mybean.person.nationality2.id}">
<f:selectItems value="#{mybean.countryList}" var="var" itemValue="#{var.id}"/>
</h:selectOneMenu>
<p:commandButton actionListener="#{mybean.save}" update="sometable @form"/>
</h:form>
奇妙な問題は、フォームを送信すると、最初のフィールドに何が選択されているかに関係なく、2番目のフィールド(nationality2)に割り当てられた値が国籍とnationality2の両方に割り当てられることです。たとえば、selected value for nationality is 1
との場合selected value for nationality2 is 2
、フォームを送信するとboth fields have the value 2
。なぜこれが起こっているのですか?
PS:JSFの実装はMojarra2.1.3です