title: render an outputText using selectOneMenu Error : java.lang.NullPointerException
body: <p>i have a problem when i try to display a field depending on the values chosen on the select one menu.
  it doesn't allow me to choose, it just display the exception. it's like it tries to get the number of children without waiting for the parameters</p>
  
  <pre><code>14-Jun-2014 13:21:08.256 SEVERE [http-nio-8084-exec-152] com.sun.faces.application.view.FaceletViewHandlingStrategy.handleRenderException Error Rendering View[/insalaire.xhtml]
   javax.el.ELException: /insalaire.xhtml @32,85 value="#{personnel1Bean.nombreEnfants}": Error reading 'nombreEnfants' on type controller.Personnel1Bean
      at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:114)
      at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
      at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
      at javax.faces.component.UIOutput.getValue(UIOutput.java:174)
      at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:205)
      at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:355)
      at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:164)
      at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919)
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1903)
      at javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
      at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:889)
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1896)
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1899)
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1899)
      at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:451)
      at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
      at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
      at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
      at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:301)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:74)
      at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1015)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:652)
      at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1575)
      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1533)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: javax.el.ELException: Error reading 'nombreEnfants' on type controller.Personnel1Bean
      at javax.el.BeanELResolver.getValue(BeanELResolver.java:108)
      at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
      at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
      at org.apache.el.parser.AstValue.getValue(AstValue.java:167)
      at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:187)
      at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
      ... 43 more
  Caused by: java.lang.NullPointerException
      at controller.Personnel1Bean.getNombreEnfants(Personnel1Bean.java:182)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:483)
      at javax.el.BeanELResolver.getValue(BeanELResolver.java:97)
      ... 48 more
  </code></pre>
  
  <p>index.xhtml</p>
  
  <pre><code> &lt;h:form id="form"&gt;
           &lt;h:panelGrid columns="2" cellpadding="5"&gt;
             &lt;h:outputText value="Nom personnel : " style="font-size: 18px" /&gt;
             &lt;p:selectOneMenu value="#{personnelBean.nom}"  &gt;
          &lt;f:selectItem itemValue="#{null}" itemLabel="--Séléctionner Nom" /&gt;
          &lt;f:selectItems value="#{personnelBean.listePersonnels}" var="personnel" 
                         itemValue="#{personnel.nom}" itemLabel="#{personnel.nom}" /&gt;
          &lt;f:ajax listener="#{personnelBean.submit()}" render="display"/&gt;
      &lt;/p:selectOneMenu&gt;
         &lt;/h:panelGrid&gt;
          &lt;h:panelGrid columns="2" cellpadding="5"&gt;
             &lt;h:outputText value="Prénom personnel : " style="font-size: 18px" /&gt;
  
             &lt;p:selectOneMenu value="#{personnel1Bean.cin}" id="display" &gt;
                  &lt;f:selectItem itemValue="#{null}" itemLabel="--Séléctionner Nom" /&gt;
          &lt;f:selectItems value="#{personnel1Bean.listePersonnels}" var="personnel" 
                         itemValue="#{personnel.cin}" itemLabel="#{personnel.prenom}" /&gt;
          &lt;f:ajax listener="#{personnel1Bean.submit()}" render="dis"/&gt;
      &lt;/p:selectOneMenu&gt;
         &lt;/h:panelGrid&gt;
                     &lt;h:outputText value="Nombre d'enfants : "/&gt;
                     &lt;h:outputText id="dis" value="#{personnel1Bean.nombreEnfants}" /&gt;
                 &lt;/h:form&gt;
  </code></pre>
  
  <p>personnel1Bean.java</p>
  
  <pre><code>package controller;
  
  import java.util.Date;
  import java.util.List;
  import javax.annotation.PostConstruct;
  import model.services.PersonnelMetier;
  import net.vo.Personnel;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.context.annotation.Scope;
  import org.springframework.stereotype.Component;
  
  @Component
  @Scope("view")
  public class Personnel1Bean {
  
      @Autowired
      private PersonnelMetier personnelMetier;
      private List&lt;Personnel&gt; listePersonnels;
      private Personnel personnel;
      private static String cin;
      private static String nom;
      private String prenom;
      private Date dateNaissance;
      private Date dateRecrutement;
      private String telephone;
      private Integer naffiliation;
      private String compteBancaire;
      private String situationFamiliale;
      private Integer nombreEnfants;
  
      @PostConstruct
      public void init() {
          listePersonnels = personnelMetier.getAllPersonnels();
      }
      public List&lt;Personnel&gt; getListePersonnels() {
          System.out.println("hhhhhhhhhhhhhhhh");
          String n = PersonnelBean.submit();
          System.out.println("2"+ n);
          listePersonnels = personnelMetier.getAllPersonnelbyNom(n);
          return listePersonnels;
      }
      public static String submit()
      {
          System.out.println("cin" + cin);
          return cin;
      }
      public Personnel getPersonnel() {
          return personnel;
      }
  
      public void setPersonnel(Personnel personnel) {
          this.personnel = personnel;
      }
  
      public void insert()
      {
          Personnel personnel = new Personnel();
          personnel.setCin(getCin());
          personnel.setNom(getNom());
          personnel.setPrenom(getPrenom());
          personnel.setDateNaissance(getDateNaissance());
          personnel.setTelephone(getTelephone());
          personnel.setDateRecrutement(getDateRecrutement());
          personnel.setCompteBancaire(getCompteBancaire());
          personnel.setNaffiliation(getNaffiliation());
          personnel.setNombreEnfants(getNombreEnfants());
          personnel.setSituationFamiliale(getSituationFamiliale());
      personnelMetier.insert(personnel);
          listePersonnels = personnelMetier.getAllPersonnels();
      }
       public void update()
      {
          System.out.println("fffffffffffffffffffffffff");
          Personnel p = personnelMetier.getPersonnel(getPersonnel().getCin());
          p.setCin(getPersonnel().getCin());
          p.setNom(getPersonnel().getNom());
          p.setPrenom(getPersonnel().getPrenom());
          p.setDateNaissance(getPersonnel().getDateNaissance());
          p.setTelephone(getPersonnel().getTelephone());
          p.setDateRecrutement(getPersonnel().getDateRecrutement());
          p.setCompteBancaire(getPersonnel().getCompteBancaire());
          p.setNaffiliation(getPersonnel().getNaffiliation());
          p.setNombreEnfants(getPersonnel().getNombreEnfants());
          p.setSituationFamiliale(getPersonnel().getSituationFamiliale());
          personnelMetier.update(personnel);
      }
      public void delete()
      {   System.out.println("fhhhhhhhhhhhhhhhhhhhhhhhhhhhhf");
          Personnel p = personnelMetier.getPersonnel(getPersonnel().getCin());
          personnelMetier.delete(getPersonnel().getCin());
          listePersonnels.remove(personnel);
          personnel = null;
      }
      public PersonnelMetier getPersonnelMetier() {
          return personnelMetier;
      }
  
      public void setPersonnelMetier(PersonnelMetier personnelMetier) {
          this.personnelMetier = personnelMetier;
      }
  
      public void setListePersonnels(List&lt;Personnel&gt; listePersonnels) {
          this.listePersonnels = listePersonnels;
      }
  
      public String getCin() {
          return cin;
      }
  
      public void setCin(String cin) {
          this.cin = cin;
      }
  
      public String getNom() {
          return nom;
      }
  
      public void setNom(String nom) {
          this.nom = nom;
      }
  
      public String getPrenom() {
          return prenom;
      }
  
      public void setPrenom(String prenom) {
          this.prenom = prenom;
      }
  
      public Date getDateNaissance() {
          return dateNaissance;
      }
  
      public void setDateNaissance(Date dateNaissance) {
          this.dateNaissance = dateNaissance;
      }
  
      public Date getDateRecrutement() {
          return dateRecrutement;
      }
  
      public void setDateRecrutement(Date dateRecrutement) {
          this.dateRecrutement = dateRecrutement;
      }
  
      public String getTelephone() {
          return telephone;
      }
  
      public void setTelephone(String telephone) {
          this.telephone = telephone;
      }
  
      public Integer getNaffiliation() {
          return naffiliation;
      }
  
      public void setNaffiliation(Integer naffiliation) {
          this.naffiliation = naffiliation;
      }
  
      public String getCompteBancaire() {
          return compteBancaire;
      }
  
      public void setCompteBancaire(String compteBancaire) {
          this.compteBancaire = compteBancaire;
      }
  
      public String getSituationFamiliale() {
          return situationFamiliale;
      }
  
      public void setSituationFamiliale(String situationFamiliale) {
          this.situationFamiliale = situationFamiliale;
      }
  
      public Integer getNombreEnfants() {
          String cin = submit();
          Personnel p = personnelMetier.getPersonnel(cin);
          nombreEnfants = p.getNombreEnfants();
          return nombreEnfants;
      }
  
      public void setNombreEnfants(Integer nombreEnfants) {
          this.nombreEnfants = nombreEnfants;
      }
  
  }
  </code></pre>
  
  <p>personnelBean.java</p>
  
  <pre><code>package controller;
  
  import java.util.Date;
  import java.util.List;
  import javax.annotation.PostConstruct;
  import model.services.PersonnelMetier;
  import net.vo.Personnel;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.context.annotation.Scope;
  import org.springframework.stereotype.Component;
  
  @Component
  @Scope("view")
  public class PersonnelBean {
  
      @Autowired
      private PersonnelMetier personnelMetier;
      private List&lt;Personnel&gt; listePersonnels;
      private Personnel personnel;
      private static String cin;
      private static String nom;
      private String prenom;
      private Date dateNaissance;
      private Date dateRecrutement;
      private String telephone;
      private Integer naffiliation;
      private String compteBancaire;
      private String situationFamiliale;
      private Integer nombreEnfants;
  
      @PostConstruct
      public void init() {
          listePersonnels = personnelMetier.getAllPersonnels();
      }
  
      public List&lt;Personnel&gt; getListePersonnels() {
          return listePersonnels;
      }
  
      public Personnel getPersonnel() {
          return personnel;
      }
  
      public void setPersonnel(Personnel personnel) {
          this.personnel = personnel;
      }
      public static String submit()
      {   
          System.out.println("1" + nom);
  
          return nom;
      }
  
      public void insert()
      {
          Personnel personnel = new Personnel();
          personnel.setCin(getCin());
          personnel.setNom(getNom());
          personnel.setPrenom(getPrenom());
          personnel.setDateNaissance(getDateNaissance());
          personnel.setTelephone(getTelephone());
          personnel.setDateRecrutement(getDateRecrutement());
          personnel.setCompteBancaire(getCompteBancaire());
          personnel.setNaffiliation(getNaffiliation());
          personnel.setNombreEnfants(getNombreEnfants());
          personnel.setSituationFamiliale(getSituationFamiliale());
      personnelMetier.insert(personnel);
          listePersonnels = personnelMetier.getAllPersonnels();
      }
       public void update()
      {
          System.out.println("fffffffffffffffffffffffff");
          Personnel p = personnelMetier.getPersonnel(getPersonnel().getCin());
          p.setCin(getPersonnel().getCin());
          p.setNom(getPersonnel().getNom());
          p.setPrenom(getPersonnel().getPrenom());
          p.setDateNaissance(getPersonnel().getDateNaissance());
          p.setTelephone(getPersonnel().getTelephone());
          p.setDateRecrutement(getPersonnel().getDateRecrutement());
          p.setCompteBancaire(getPersonnel().getCompteBancaire());
          p.setNaffiliation(getPersonnel().getNaffiliation());
          p.setNombreEnfants(getPersonnel().getNombreEnfants());
          p.setSituationFamiliale(getPersonnel().getSituationFamiliale());
          personnelMetier.update(personnel);
      }
      public void delete()
      {   System.out.println("fhhhhhhhhhhhhhhhhhhhhhhhhhhhhf");
          Personnel p = personnelMetier.getPersonnel(getPersonnel().getCin());
          personnelMetier.delete(getPersonnel().getCin());
          listePersonnels.remove(personnel);
          personnel = null;
      }
      public PersonnelMetier getPersonnelMetier() {
          return personnelMetier;
      }
  
      public void setPersonnelMetier(PersonnelMetier personnelMetier) {
          this.personnelMetier = personnelMetier;
      }
  
      public void setListePersonnels(List&lt;Personnel&gt; listePersonnels) {
          this.listePersonnels = listePersonnels;
      }
  
      public String getCin() {
          return cin;
      }
  
      public void setCin(String cin) {
          this.cin = cin;
      }
  
      public String getNom() {
          return nom;
      }
  
      public void setNom(String nom) {
          this.nom = nom;
      }
  
      public String getPrenom() {
          return prenom;
      }
  
      public void setPrenom(String prenom) {
          this.prenom = prenom;
      }
  
      public Date getDateNaissance() {
          return dateNaissance;
      }
  
      public void setDateNaissance(Date dateNaissance) {
          this.dateNaissance = dateNaissance;
      }
  
      public Date getDateRecrutement() {
          return dateRecrutement;
      }
  
      public void setDateRecrutement(Date dateRecrutement) {
          this.dateRecrutement = dateRecrutement;
      }
  
      public String getTelephone() {
          return telephone;
      }
  
      public void setTelephone(String telephone) {
          this.telephone = telephone;
      }
  
      public Integer getNaffiliation() {
          return naffiliation;
      }
  
      public void setNaffiliation(Integer naffiliation) {
          this.naffiliation = naffiliation;
      }
  
      public String getCompteBancaire() {
          return compteBancaire;
      }
  
      public void setCompteBancaire(String compteBancaire) {
          this.compteBancaire = compteBancaire;
      }
  
      public String getSituationFamiliale() {
          return situationFamiliale;
      }
  
      public void setSituationFamiliale(String situationFamiliale) {
          this.situationFamiliale = situationFamiliale;
      }
  
      public Integer getNombreEnfants() {
          return nombreEnfants;
      }
  
      public void setNombreEnfants(Integer nombreEnfants) {
          this.nombreEnfants = nombreEnfants;
      }
  
  }
  </code></pre>
  
  <p><strong>edit :</strong>
  i made some changes : 
  i removed the business logic from the getter. now i don't get the exception,but i don't get the value of the field when i choose. i don't access to method loadNombreEnfants()</p>
  
  <p>Personnel1Bean</p>
  
  <pre><code> public void ajaxListener(AjaxBehaviorEvent event) {
  
          nombreEnfants = loadNombreEnfants();
      }
   private Integer loadNombreEnfants() {
          System.out.println("FFFFFFFFFFF");
          String cin = submit();
          System.out.println("CIN" + cin);
          Personnel p = personnelMetier.getPersonnel(cin);
          nombreEnfants = p.getNombreEnfants();
          System.out.println(nombreEnfants);
          return nombreEnfants;
      }
   public Integer getNombreEnfants() {
          return nombreEnfants;
      }
  </code></pre>