简体   繁体   English

通过对话框组件更新SelectOneMenu primefaces组件

[英]Update the SelectOneMenu primefaces component through a dialog component

I'm running an address lookup by zip in a dialog component to refresh the form with address data. 我正在对话框组件中通过zip运行地址查找,以使用地址数据刷新表单。 The address object is correct with all the information, but the city and neighborhood component is not processed with the appropriate information. 地址对象对于所有信息都是正确的,但是没有使用适当的信息来处理城市和邻里部分。 Only the state component is loaded 仅加载状态组件

The selection components are dependent, State, City, and Neighborhood 选择组件取决于从属,州,城市和邻里

Page Address 页面地址

<h:form id="formEnd">
    <p:panelGrid id="pnlEnderecoID" columns="2" layout="grid" columnClasses="ui-grid-col-2, ui-grid-col-5" styleClass="ui-panelgrid-blank">

        <p:outputLabel value="Cep:"/>
        <p:outputPanel>
            <p:inputText id="iptCepID" value="#{funcionarioBean.endereco.cep}" style="width: 180px;">
                <sgr:onlyNumber/>
            </p:inputText>
            <p:commandLink onclick="PF('cepDLG').show();" process="@this">
                <span class="label label-primary"><i class="fa fa-search"></i></span>
            </p:commandLink>
        </p:outputPanel>

        <p:outputLabel value="Estado:"/>
        <p:selectOneMenu id="selectEstadoID" value="#{funcionarioBean.endereco.bairro.cidade.estado}" converter="omnifaces.SelectItemsConverter">
            <f:selectItem itemLabel="Selecione" itemValue="" noSelectionOption="true"/>
            <f:selectItems value="#{funcionarioBean.listaEstados}" var="obj" itemLabel="#{obj.descricao}" itemValue="#{obj}"/>
            <p:ajax listener="#{funcionarioBean.buscarCidadesPorEstadoSelecionado}" update="selectCidadeID"/>
        </p:selectOneMenu>

        <p:outputLabel value="Cidade:"/>
        <p:selectOneMenu id="selectCidadeID" value="#{funcionarioBean.endereco.bairro.cidade}" converter="omnifaces.SelectItemsConverter">
            <f:selectItem itemLabel="Selecione" itemValue="" noSelectionOption="true"/>
            <f:selectItems value="#{funcionarioBean.listaCidades}" var="obj" itemLabel="#{obj.descricao}" itemValue="#{obj}"/>
            <p:ajax listener="#{funcionarioBean.buscarBairrosPorCidadeSelecionada}" update="selectBairroID"/>
        </p:selectOneMenu>

        <p:outputLabel value="Bairro:"/>
        <p:selectOneMenu id="selectBairroID" value="#{funcionarioBean.endereco.bairro}" converter="omnifaces.SelectItemsConverter">
            <f:selectItem itemLabel="Selecione" itemValue="" noSelectionOption="true"/>
            <f:selectItems value="#{funcionarioBean.listaBairros}" var="obj" itemLabel="#{obj.descricao}" itemValue="#{obj}"/>
        </p:selectOneMenu>

    </p:panelGrid>
</h:form>

<p:dialog header="Pesquisar CEP" widgetVar="cepDLG" modal="true" height="100">
    <h:form id="formDLG">
        <p:inputText id="iptCepWS" placeholder="Digite o CEP" value="#{funcionarioBean.endereco.cep}"/>
        <p:commandButton
                    action="#{funcionarioBean.pesquisaCepComplementaEndereco}"
                    process="@this, iptCepWS"
                    update=":pnlEnderecoID"
                    style="width: 50px;"
                    icon="fa fa-search" oncomplete="PF('cepDLG').hide()"/>
    </h:form>
</p:dialog>

Image after rendering formEnd by Dialog 渲染表单后的图像

在此处输入图片说明

I was able to solve the problem by loading the city and neighborhood list after loading the form. 加载表格后,我可以通过加载城市和街区列表来解决此问题。 Thank you for the help @Jaqen H'ghar 谢谢您的帮助@Jaqen H'ghar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM