Change Selectonemenu

4

I'm working with the Parents, Province, and City tables using JSF, Primefaces, and EJBs. But running 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>
    
asked by anonymous 25.12.2015 / 16:23

1 answer

1

In Bean, create a method called init and start the Parent object inside the Province object like this:

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

The Nullpointer is given because it tried to access the Parent object within Providence which was not instantiated, it was null.

    
22.01.2016 / 20:23