Jsf primefaces下拉列表更新仅在验证失败期间失败

时间:2015-10-30 17:39:02

标签: ajax jsf primefaces dropdown

我有一个下拉列表(id =" localOffInputId"),其值需要根据文本框输入进行修改(id =" rZip")。当表单中没有验证错误时,它可以正常工作。发生验证错误时,表单将按预期重新显示错误消息。现在,当我更改文本框中的值时,将调用侦听器方法(updateLocalOffice())并将localOfficeCode设置为新值,但下拉选择在浏览器中不会更改。我注意到,尽管调用了localOfficeMap的getter,但是在调用ajax之后没有调用localOfficeCode属性的getter。知道为什么只有在验证失败时才会发生这种情况?

<p:row>
    <p:column>
        <h:panelGroup id="resZipInputId">
            <p:inputMask id="rZip" value="#{createProfile.profileForm.rZip}" mask="99999" size="5" required="true" requiredMessage="#{msg['msg.physical.zip.required']}" valueChangeListener="#{createProfile.addDirtyFields}">
                <f:attribute name="fieldName" value="Physical Address - ZIP" />
                <f:attribute name="fieldOrder" value="24"/>
                <p:ajax event="change" listener="#{createProfile.profileForm.updateLocalOffice}" update="localOfficeTableId,localOffInputId, localOfficeDropdownId" />
            </p:inputMask>
            <h:outputText value=" - "/>
            <p:inputMask value="#{createProfile.profileForm.rZipPlus4}" mask="9999" size="4" valueChangeListener="#{createProfile.addDirtyFields}"></p:inputMask>
        </h:panelGroup>
    </p:column>
</p:row>

<p:row>
    <p:column colspan="2">
        <h:panelGroup id="localOfficeTableId">
            <p:panelGrid styleClass="noBorderPanelGrid">
                <p:row>
                    <p:column>
                        <h:panelGroup id="localOffInputId">
                            <h:selectOneMenu value="#{createProfile.profileForm.localOfficeCode}" id="localOfficeDropdownId" valueChangeListener="#{createProfile.addDirtyFields}" required="true" requiredMessage="#{msg['msg.localoffice.required']}">
                                <f:selectItems value="#{createProfile.profileForm.localOfficeMap}" />
                            </h:selectOneMenu>
                        </h:panelGroup>
                    </p:column>
                </p:row>
            </p:panelGrid>
        </h:panelGroup>
    </p:column>
</p:row>

public void updateLocalOffice(){
    final String resZip = this.rZip;
    if (StringUtils.isNotBlank(resZip)) {
        final String localOfficeCodeForZip = this.service
                .getLocalOfficeCodeForZip(this.rZip);

        if (StringUtils.isNotBlank(localOfficeCodeForZip)) {
            this.setLocalOfficeCode(localOfficeCodeForZip);
        } else {
            this.setLocalOfficeCode(Constants.OOS_CODE);
        }
    }
}

1 个答案:

答案 0 :(得分:0)

找到问题的答案。添加&#34; resetValues =&#34; true&#34;&#34;到ajax调用修复了这个问题     

链接 - How can I populate a text field using PrimeFaces AJAX after validation errors occur?