I have the following JSF-Code:
<p:selectOneRadio id="contactPersonGender" value="#{myBean.contactPersonGender}">
<f:selectItems value="#{data.getGenders()}" var="gender" itemValue="#{gender}" itemLabel="#{gender.label}" />
</p:selectOneRadio>
<p:commandButton onclick="copyFromContactToManager();" ajax="false" type="button" update="@form"/>
<p:selectOneRadio id="managerGender" value="#{myBean.managerGender}">
<f:selectItems value="#{data.getGenders()}" var="gender" itemValue="#{gender}" itemLabel="#{gender.label}" />
</p:selectOneRadio>
I now want to copy the selection from contactPersonGender to managerGender when the button is clicked. data.getGenders() returns an array of the enum type "Gender" (MALE or FEMALE). So for example when FEMALE is selected in contactPersonGender then managerGender should also get FEMALE selected when the button is clicked.
I have tried the following codes:
function copyFromContactToManager(){
$("input[id^='" + contactPersonGender + "']").each(function(index, element) {
if ($(element).prop("checked")) {
$("input[id^='managerGender:" + index + "']").first().click();
}
});
}
OR:
function copyFromContactToManager(){
$("input[id^='" + contactPersonGender + "']").each(function(index, element) {
$("input[id^='managerGender:" + index + "']").prop("checked", $(element).prop("checked"));
}
}
Both of them work, but the UI is not updated after performing a click on my button (So for example if in contactPersonGender "MALE" is selected and in managerGender "FEMALE" is selected, after clicking the button in managerGender "FEMALE" seems still to be selected. But if I send the form to the server and persist the data, managerGender has the expected value of "MALE").