I have two autocomplete fields as below. I swap the autocomplete values using a command button. I need to persist the swapped values.
<p:column colspan="2" rendered="#{empty contactController.selectedContact}">
<p:autoComplete id="contactName1" value="#{newContactRs.contact}"
completeMethod="#{contactRelationshipController.completeContacts}"
var="contact" itemLabel="#{contact.fullName}"
itemValue="#{contact}" converter="#{contactConverter}"
forceSelection="true" size="35" scrollHeight="200"
panelStyle="width:10px;">
<p:ajax event="itemSelect" update="contactName1" />
</p:autoComplete>
<p:commandButton icon="ui-icon-arrow-2-e-w" id="flipButton"
styleClass="ui-panel-titlebar-icon" oncomplete="swapInput()" update="addNewContactRelationshipPanel" immediate="true"/>
<smith:contactSelector value="#{newContactRs.contact}" update=":addContactRelationshipForm:addNewContactRelationshipPanel" triggerId="existingContactSelector1" resultList="#{contactRelationshipController.selectAllContact1}"/>
</p:column>
<p:column colspan="2">
<p:autoComplete id="contactName2" value="#{newContactRs.relatedContact}"
completeMethod="#{contactRelationshipController.completeContacts}"
var="contact" itemLabel="#{contact.fullName}"
itemValue="#{contact}" converter="#{contactConverter}"
forceSelection="true" size="35" scrollHeight="200"
panelStyle="width:10px;">
<p:ajax event="itemSelect" update="contactName2" />
</p:autoComplete>
<smith:contactSelector value="#{newContactRs.relatedContact}" update=":addContactRelationshipForm:addNewContactRelationshipPanel" triggerId="existingContactSelector2" resultList="#{contactRelationshipController.selectAllContact2}"/>
</p:column>
On clicking the commandbutton with id "flipButton" following javascript is called and it swaps the values of the autocomplete fields
function swapInput()
{
var input_a =document.getElementById('addContactRelationshipForm:contactName1_input').value;
var input_b =document.getElementById('addContactRelationshipForm:contactName2_input').value;
document.getElementById('addContactRelationshipForm:contactName1_input').value = input_b;
document.getElementById('addContactRelationshipForm:contactName2_input').value = input_a;
}
After swapping the values am trying to persist the swapped values but original values are persisting instead of swapped values. I have to set the swapped values in the backing bean but am not sure how to do it, using javascript or primefaces.