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 ofp:ajax
.– BrTkCa
Whoa, bro, I’ve tried that option.
– Rodrigo Costa
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
– Paulo
He comes to call for the bean?
– Marcus Martins
2 options for you: Put the components of your comboState in one
panelGrid
and have it updated. In your ajax, you must have theevent="change"
. Leave your method without parameters and add oneprocess="@form"
in your comboPaises.– Roknauta
Tried <p:ajax Event="change" update="comboEstados" Listener="#{comboMB.buscar}" /> and switch the bean to public void fetch() ?
– Marcus Martins
Good morning sorry for the delay, Marcus he does not call to fetch in the bean.
– Rodrigo Costa
@Douglas made another panelGrid, put Event, took the parameters and put the process in selectOneMenu of the comboPaises'
– Rodrigo Costa
@Marcusmartins yes , I’ve done it there too.
– Rodrigo Costa
@Paul I will try this option and soon I reply.
– Rodrigo Costa
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.
– Marcus Martins
@Marcusmartins tested this option now and nothing.
– Rodrigo Costa
But he at least set the country? Or he’s not even calling the setPais?
– Marcus Martins
he’s not even calling the setPais.
– Rodrigo Costa
People put the Serializable in the entities Parents and State and now it calls the ajax,
– Rodrigo Costa
Resolved then @Rodrigocosta?
– Roknauta
SOLVED ! THANK YOU ALL.
– Rodrigo Costa