3

我有两个自动完成字段,如下所示。我使用命令按钮交换自动完成值。我需要保留交换的值。

    <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。

4

2 回答 2

1

您可以使用 Preimefaces p:remoteCommand 来执行托管 bean 方法。 https://www.primefaces.org/showcase/ui/ajax/remoteCommand.xhtml

于 2013-09-12T03:52:12.900 回答
0

更改commandButton

<p:commandButton icon="ui-icon-arrow-2-e-w" 
                 id="flipButton" 
                 styleClass="ui-panel-titlebar-icon" 
                 oncomplete="swapInput()" 
                 update="addNewContactRelationshipPanel" 
                 immediate="true" 
                 process="@this" 
                 actionListener="#{contactRelationshipController.setSwapInputFlag()}"/>

然后检查swapInputFlag同时保留自动完成字段。

于 2013-09-12T19:33:12.827 回答