我有两个自动完成字段,如下所示。我使用命令按钮交换自动完成值。我需要保留交换的值。
<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>
单击 id 为“flipButton”的命令按钮后调用 javascript 并交换自动完成字段的值
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;
}
交换值后,我试图保留交换的值,但保留原始值而不是交换值。我必须在支持 bean 中设置交换的值,但不知道如何使用 javascript 或 primefaces。