PrimeFaces - 第二个下拉列表中的验证错误(依赖selectOneMenus) - RequestScoped

时间:2014-06-04 19:29:10

标签: ajax jsf primefaces

第二个下拉列表正在由AJAX填充,但其中存在验证错误。即使列表填充正确并进行了选择。

<h:form id="form">
        <p:growl id="growl" showDetail="true" sticky="true" globalOnly="true" />

        <h:panelGrid columns="3">
            <p:outputLabel for="nome" value="Nome:" />
            <p:inputText id="nome" value="#{estadoMB.estado.nome}" required="true" validatorMessage="Nome incorreto!" />
            <p:message for="nome" />

            <p:outputLabel for="sigla" value="Sigla:" />
            <p:inputText id="sigla" value="#{estadoMB.estado.sigla}" maxlength="3" size="3" required="true" validatorMessage="Sigla incorreta!" />
            <p:message for="sigla" />

            <p:outputLabel for="continentes" value="Continente:" />
            <p:selectOneMenu id="continentes" value="#{estadoMB.continenteId}" validatorMessage="Selecione um continente!"> <!-- required="# {not empty param[submit.clientId]}" binding="# {menuContinentes}" -->
                <f:selectItem  itemValue="" itemLabel="-- Selecione --" noSelectionOption="true" />
                <f:selectItems value="#{continenteMB.continentes}" var="continente" itemLabel="#{continente.nome}" itemValue="#{continente.id}" />
                <p:ajax event="change" listener="#{estadoMB.onPaisesChange}" update="paises" />
            </p:selectOneMenu>
            <p:message for="continentes" />

            <p:outputLabel for="paises" value="País:" />
            <p:selectOneMenu id="paises" value="#{estadoMB.pais.id}" validatorMessage="Selecione um país!"> <!-- required="# {not empty param[menuContinentes.clientId]or not empty param[submit.clientId]}" -->
                <f:selectItem  itemValue="" itemLabel="-- Selecione --" noSelectionOption="true" />
                <f:selectItems value="#{estadoMB.paisesCarregados}" var="pais" itemLabel="#{pais.nome}" itemValue="#{pais.id}" />
            </p:selectOneMenu>
            <p:message for="paises" />

            <p:commandButton action="#{estadoMB.save}" value="Salvar" update="@form" /> <!-- binding="# {submit}" -->
        </h:panelGrid>
    </h:form>

方法onPaisesChange

public void onPaisesChange() {
    if(pais != null) {
        Map<String, Object> map = new HashMap<>();
        map.put("id", getContinenteId());
        paisesCarregados = paisBean.findWithNamedQuery("Pais.findByContinenteId", map);
    }
    else {
        paisesCarregados = new ArrayList<>();
    }
}

已经尝试过EL绑定;两者中required =“true”,我得到了相同的结果。

我认为使用请求范围的bean来做我想做的事情是不可能的......

0 个答案:

没有答案