我有两个自动填充字段,如下所示。我使用命令按钮交换自动完成值。我需要保持交换的值。
<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>
在点击javascript后,点击id为“flipButton”的命令按钮,它会交换自动填充字段的值
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。
答案 0 :(得分:1)
您可以使用Preimefaces p:remoteCommand来执行托管bean方法。 https://www.primefaces.org/showcase/ui/ajax/remoteCommand.xhtml
答案 1 :(得分: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
。