0

I'm running an address lookup by zip in a dialog component to refresh the form with address data. 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

enter image description here

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Ger
  • 583
  • 2
  • 13
  • 35
  • 2
    Could you try with update=":formEnd:pnlEnderecoID" (or just ":formEnd") – Jaqen H'ghar Jun 17 '17 at 07:11
  • See https://stackoverflow.com/questions/6045307/how-can-i-know-the-id-of-a-jsf-component-so-i-can-use-in-javascript effectively a 'duplicate' – Kukeltje Jun 17 '17 at 10:33
  • Thanks for the reply Jaqen H'ghar. But the same result of the image of my question occurred. I am not understanding this behavior in these Dependent components – Ger Jun 17 '17 at 16:06
  • You've checked up on the toString() since using the Omnifaces converter? – Jaqen H'ghar Jun 17 '17 at 17:53
  • Thanks for the answer. Jaqen H'ghar. All Entities I am using on this screen have the ToString () implementation returning only one Entity field. I even tested it with an alternate converter I implemented. The result was the same. – Ger Jun 18 '17 at 00:19
  • I believe the problem is in the ajax event of the selectOneMenu component. After the form is rendered, clicking the "State" selection component and changing it to another value and then returning the original value, the "City" selection component is populated with the correct city – Ger Jun 18 '17 at 00:31
  • I discovered the cause but not the problem. The City and Neighborhood selection component is loaded by state selection. Therefore the City and Neighborhood list is empty until a state is selected. If the lists are filled the components are loaded normally – Ger Jun 18 '17 at 01:28
  • Could you try with itemValue="#{null}" on the noSelectionOption's. Otherwise we need a mvce so we can replicate – Jaqen H'ghar Jun 18 '17 at 07:39
  • Thank you for your help @Jaqen H'ghar. But I was able to solve the problem by loading the city and neighborhood list after loading the form. – Ger Jun 18 '17 at 20:41

1 Answers1

0

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

Ger
  • 583
  • 2
  • 13
  • 35