【问题标题】:Jsf primefaces dropdown updated fails only during validation failure [duplicate]仅在验证失败期间更新的 Jsf primefaces 下拉列表失败 [重复]
【发布时间】:2016-01-31 05:24:18
【问题描述】:

我有一个下拉列表 (id="localOffInputId"),它的值需要根据文本框输入 (id="rZip") 进行修改。当表单中没有验证错误时,它可以正常工作。当发生验证错误时,表单会按预期重新显示错误消息。现在,当我更改文本框中的值时,将调用侦听器方法 (updateLocalOffice()) 并将 localOfficeCode 设置为新值,但浏览器中的下拉选择不会更改。我注意到 localOfficeCode 属性的 getter 在 ajax 调用之后没有被调用,尽管 localOfficeMap 的 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);
        }
    }
}

【问题讨论】:

    标签: ajax jsf primefaces dropdown


    【解决方案1】:

    找到问题的答案。将“resetValues="true"” 添加到 ajax 调用解决了这个问题

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

    【讨论】:

      猜你喜欢
      • 2012-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-08
      • 2013-02-28
      • 1970-01-01
      • 2014-11-01
      • 2011-09-09
      相关资源
      最近更新 更多