Ajax does not work, selectOneMenu cascading

Asked

Viewed 400 times

0

I am developing a program but ajax does not work at all. I decided to make a very simple system to see where the error is and still can not a solution. I saw some of that on the forum but I couldn’t either. HTML

        <h:outputText value="Pais: " />
        <p:selectOneMenu id="comboPais" process="@this" converter="conversorObjetoId" value="#{comboMB.pais}">
            <f:selectItem itemLabel="--Selecione--" itemValue="" />
            <f:selectItems value="#{comboMB.paises}" var="pais" itemLabel="#{pais.nome}" itemValue="#{pais}" />
            <p:ajax event="change" update="comboEstados" actionListener="#{comboMB.buscar()}" />            </p:selectOneMenu>

        <h:outputText value="Estados: " />
            <p:selectOneMenu id="comboEstados" value="#{vendasMB.estado}">
                    <f:selectItem itemLabel="--Selecione--" itemValue="" />
                    <f:selectItems value="#{vendasMB.estados}" var="estado"  itemLabel="#{estado.nome}" itemValue="#{estado}" />    
                </p:selectOneMenu>      </h:panelGrid>      </p:panel> </h:form>

The index I have changed several things I have left onChange, I have already updated, Several attempts

@Viewscoped @Managedbean

@PostConstruct
public void init() {
    paises = dao.consultarPais();
    System.out.println("--> init*()");
}

public void buscar(ActionEvent event) {
    estados = dao.consultarEstados(pais);
}

UPDATED

    <h:form id="frmTeste">
<p:outputPanel id="cadastroCidades">
        <h:panelGrid id="painel" columns="2">

            <p:outputLabel for="comboPaises" value="Pais: " />
            <p:selectOneMenu id="comboPaises" converter="conversorObjetoId"  value="#{comboMB.pais}">
                <f:selectItem itemLabel="--Selecione--" itemValue="" />
                <f:selectItems value="#{comboMB.paises}" var="pais" itemLabel="#{pais.nome}" itemValue="#{pais}" />
                <p:ajax listener="#{comboMB.buscar}" update="comboEstados" />
            </p:selectOneMenu>

            <p:outputLabel for="comboEstados"   value="Estados: " />
                <p:selectOneMenu id="comboEstados" converter="conversorObjetoId"  value="#{vendasMB.estado}">
                        <f:selectItem itemLabel="--Selecione--" itemValue="" />
                        <f:selectItems value="#{vendasMB.estados}" var="estado"  itemLabel="#{estado.nome}" itemValue="#{estado}" />    
                    </p:selectOneMenu>
        </h:panelGrid>
        </p:outputPanel>
</h:form>
  • If you can, try using the JSF ajax, the f:ajax instead of p:ajax.

  • Whoa, bro, I’ve tried that option.

  • You have already tried to remove the search method parameter from your Bean. And query the dao using getPais() as the search parameter ? Since this getPais() is the object set in the value of the selectOneMenu when it is processed after the value change of the select

  • He comes to call for the bean?

  • 2 options for you: Put the components of your comboState in one panelGrid and have it updated. In your ajax, you must have the event="change". Leave your method without parameters and add one process="@form" in your comboPaises.

  • Tried <p:ajax Event="change" update="comboEstados" Listener="#{comboMB.buscar}" /> and switch the bean to public void fetch() ?

  • Good morning sorry for the delay, Marcus he does not call to fetch in the bean.

  • @Douglas made another panelGrid, put Event, took the parameters and put the process in selectOneMenu of the comboPaises'

  • @Marcusmartins yes , I’ve done it there too.

  • @Paul I will try this option and soon I reply.

  • Well... then test the following: take out the Systener from p:ajax, leave only the update. In the bean, put the fetch() inside the setPais() method. In that case, every time it sets the country, it will update the states.

  • @Marcusmartins tested this option now and nothing.

  • But he at least set the country? Or he’s not even calling the setPais?

  • he’s not even calling the setPais.

  • People put the Serializable in the entities Parents and State and now it calls the ajax,

  • Resolved then @Rodrigocosta?

  • SOLVED ! THANK YOU ALL.

Show 12 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.