Good morning, friends! I am a beginner in Java and I am trying to develop a system for church management. After many attempts, I can make ajax work, however I am not able to retrieve the id of the state that was selected in selectOneMenu. The id returned is always null. Here are snippets of code:
<h:form id="formMembroCadastro">
<h:panelGrid id="panel2" columns="4">
<p:outputLabel for="estado" value="Estado: "
style="margin-left: 30px" />
<p:selectOneMenu id="estado" value="#
{membroBean.membro.endereco.bairro.cidade.estado}"
readonly="#{membroBean.acao == 'Consultar'}">
<p:ajax listener="#{membroBean.getCidadesDoBanco}"
immediate="true" update=":formMembroCadastro:cidade" />
<f:selectItem itemValue="" itemLabel="Escolha o estado"
noSelectionOption="true" />
<f:selectItems value="#{membroBean.estados}" var="estado"
itemValue="#{estado.id}" itemLabel="#
{estado.nome}" />
</p:selectOneMenu>
</h:panelGrid>
</h:form>
I have already changed several things, like @ViewScoped, @SessionScoped, event, listener, update.
@ManagedBean
@ViewScoped
public class MembroBean implements Serializable {
private static final long serialVersionUID = 1L;
private Membro membro = new Membro();
private Estado estado;
public void getCidadesDoBanco() {
System.out.println(estado.getId());
cidades = new DAO<Cidade>(Cidade.class).listaGeral();
}
}
When I put
System.out.println(Estado.class);
prints "class br.com .modelo.Estado".
Thank you in advance for your help.