0
Good afternoon, I have two selects one menu, one loads the states and the other I want to load the cities of that state at runtime, only I can’t, it doesn’t even load the page when I try to use <p:ajax>
or <f:ajax>
, someone can give me a hand:
Bean
private EstadoDAO edao = new EstadoDAO();
private List<Estado> estados;
private int estadoSelecionado;
private CidadeDAO cdao = new CidadeDAO();
private List<Cidade> cidades;
private int cidadeSelecionada;
public pessoaMB() {
estados = edao.MostrarEstados();
}
public void atualizarCidadesporEstado() {
cidades = cdao.MostrarCidadesporEstado(estadoSelecionado);
}
My canvas:
<div class="ui-g-12">
<h:selectOneMenu id="estado" value="#{pessoaMB.estadoSelecionado}" >
<f:selectItems value="#{pessoaMB.estados}" var="estado" itemValue="#{estado.idEstado}" itemLabel="#{estado.nomeEstado}"/>
</h:selectOneMenu>
<p:ajax update="cidade" listener="#{pessoaMB.atualizarCidadesporEstado()}"/>
</div>
<div class="ui-g-12">
<p:outputLabel value="Selecione sua cidade:*"/>
</div>
<div class="ui-g-12">
<h:selectOneMenu id="cidade" value="#{pessoaMB.cidadeSelecionada}" >
<f:selectItems value="#{pessoaMB.cidades}" var="cidade" itemValue="#{cidade.idCidade}" itemLabel="#{cidade.nomeCidade}"/>
</h:selectOneMenu>
</div>
DAO methods work perfectly, my problem is when I try to apply an ajax, it gets the page like this:
Very probably my logic is wrong, I have used ajax with radio button in other forms and it worked perfectly, if someone can give a north I thank.
*I’ve seen the examples of select with rendered, none worked so far with me.
It gave the same incorrect redirect error, just tell me, this logic that I applied should work ? And my method is not an event, I don’t know how it should be to work
– slyfer
Yes it is so, I was seeing something here, put the p:ajax "inside" of selectOneMenu
– André
Below is the example in the first faces showcase https://www.primefaces.org/showcase/ui/ajax/dropdown.xhtml
– André
It worked, thank you very much, the only thing is that he needs to click on some other part of the screen to render, but this I turn around, it was really worth!
– slyfer