Change Selectonemenu

Asked

Viewed 152 times

4

I am working with the tables Parents, Province and Municipality, using JSF, Primefaces and Ejbs. But when executing the Project gives the following error:

javax.faces.Facesexception: /location.xhtml @131,83 value="#{utilBean.AProvincia.fkPais.pkPais}": Target Unreachable, 'null' returned null

My Bean:

public void gravarProvincia() {
   provinciaFacade.create(NProvincia);
   NProvincia = new Provincia();
}

public void alterarProvincia() {
   AProvincia.setFkPais(new Pais(AProvincia.getFkPais().getPkPais()));
   provinciaFacade.edit(AProvincia);
   AProvincia = new Provincia();
}

public void removerProvincia() {
   provinciaFacade.remove(AProvincia);
}

public List<Provincia> todasProvincias() {
    return provinciaFacade.findAll();
}

My XML:

<p:dialog id="dlgAProvincia" widgetVar="w_dlgAProvincia">
   <p:panelGrid columns="2">
      País:
      <p:selectOneMenu value="#{utilBean.AProvincia.fkPais.pkPais}">
         <f:selectItem itemLabel="Escolhe o Pais"/>
         <f:selectItems value="#{utilBean.todosPaises()}" var="aProvinciaPaisVar" itemLabel="#{aProvinciaPaisVar.descricao}" itemValue="#{aProvinciaPaisVar.pkPais}"/>
      </p:selectOneMenu>

      Província:
      <p:inputText value="#{utilBean.AProvincia.descricao}"/>
   </p:panelGrid>
   <center>
      <p:commandButton value="Gravar" action="#{utilBean.alterarProvincia()}" oncomplete="w_dlgAProvincia.hide()" update="frmPais"/>
      <p:commandButton value="Cancelar" oncomplete="w_dlgAProvincia.hide()"/>
   </center>

</p:dialog>

1 answer

1

In Bean create a method called init and start the Parents object inside the Provincia object like this:

@PostConstruct
public void init() {
   AProvincia = new Provincia();
   AProvincia.setFkPais(new Pais());
}

The Nullpointer if gives because tried to access the object Parents inside Provicincia that was not instantiated, was null.

Browser other questions tagged

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