0

I have a drop down (id="localOffInputId"), the value of which needs to be modified based on a text box input (id="rZip"). It works fine when there are no validation errors in the form. When a validation error occurs, the form gets redisplayed with the error messages as expected. Now when I change the value in the text box, the listener method (updateLocalOffice()) gets called and the localOfficeCode gets set to a new value but the drop down selection does not change in the browser. I noticed that the getter for the localOfficeCode property is not called after the ajax call though the getter for the localOfficeMap is getting called. Any idea why this happens only when validation failure occurs?

<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);
        }
    }
}
Jude
  • 7
  • 3

1 Answers1

0

Found answer to the problem. Adding "resetValues="true"" to the ajax call fixed the issue

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

Community
  • 1
  • 1
Jude
  • 7
  • 3