Problems with <p:ajax> on primefaces

Asked

Viewed 142 times

0

Good morning friends! I am a beginner in Java and am trying to develop a system for church management. After many attempts, I can make ajax work, but I am not able to recover the id of the state that was selected in selectOneMenu. The returned id is always null. Follows snippets of the 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’ve changed a lot of 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.igreja.modelo.Estado".

From now on I thank anyone who can help.

  • I found that the following error is occurring: "Conversion error when setting the value '3' to 'null Converter". Where the value 3 is the id of the selected state.

1 answer

0


Your p:selectOneMenu is waiting for an object State but you are passing the state id. You can change xhtml:

    <p:selectOneMenu id="estado" value="#
                 {membroBean.membro.endereco.bairro.cidade.estado}"
                 readonly="#{membroBean.acao == 'Consultar'}">
        ...
        <f:selectItems value="#{membroBean.estados}" var="estado"
                       itemValue="#{estado}" itemLabel="#
                       {estado.nome}" />
    </p:selectOneMenu>
  • Thank you for answering André! In addition to applying your tip, I also used the omniface converter.

Browser other questions tagged

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