title: Error : javax.el.PropertyNotFoundException: Target Unreachable, 'null' returned null
body: <p>I got this error below when I was running my JSF page.</p>
  
  <p>javax.el.PropertyNotFoundException: Target Unreachable, 'null' returned null..</p>
  
  <blockquote>
    <p>Warning:   /createStaff.xhtml @33,125
    value="#{staffBean.staff.firstName}": Target Unreachable, 'null'
    returned null javax.el.PropertyNotFoundException: /createStaff.xhtml
    @33,125 value="#{staffBean.staff.firstName}": Target Unreachable,
    'null' returned null</p>
  </blockquote>
  
  <p>I don't get why I will run into the error when I use value=<code>"#{staffBean.staff.firstName}"</code>. There is no problem when I use the value=<code>"#{staffBean.userName}"</code> and value=<code>"#{staffBean.passWord}"</code> above.</p>
  
  <p>This is my createStaff.xhtml</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8' ?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://xmlns.jcp.org/jsf/html"
        xmlns:f="http://xmlns.jcp.org/jsf/core"
        xmlns:p="http://primefaces.org/ui"&gt;
      &lt;h:head&gt;
          &lt;title&gt;Create Staff&lt;/title&gt;
      &lt;/h:head&gt;
      &lt;h:body&gt;
          &lt;f:view&gt;
              &lt;h:form&gt;
                  &lt;p:panel id ="panel" header="Staff Creation"&gt;
                      &lt;p:messages id="msgs" /&gt;
                      &lt;h:panelGrid columns="3" columnClasses="label, value"&gt;
                          &lt;h:outputText value="Username: *" /&gt;
                          &lt;p:inputText id="username" value="#{staffBean.userName}"   required="true" label="Username"&gt;
                          &lt;/p:inputText&gt;
                          &lt;p:message for="username" /&gt;
  
                          &lt;h:outputLabel for="pwd1" value="Password 1: *" /&gt;
                          &lt;p:password id="pwd1" value="#{staffBean.passWord}" match="pwd2" label="Password 1" required="true" feedback="true" /&gt;
                          &lt;p:message for="pwd1" /&gt;
  
                          &lt;h:outputLabel for="pwd2" value="Password 2: *" /&gt;
                          &lt;p:password id="pwd2" value="#{staffBean.passWord}" label="Password 2" required="true" feedback="true" /&gt;
                          &lt;p:message for="pwd2" /&gt;
  
                          &lt;h:outputText value="First name: *" /&gt;
                          &lt;p:inputText id="firstname" value="#{staffBean.staff.firstName}"   required="true" label="Username"&gt;
                          &lt;/p:inputText&gt;
                          &lt;p:message for="firstname" /&gt;
  
                          &lt;h:outputText value="Last name: *" /&gt;
                          &lt;p:inputText id="lastname" value="#{staffBean.staff.lastName}"   required="true" label="Username"&gt;
                          &lt;/p:inputText&gt;
                          &lt;p:message for="lastname" /&gt;
  
                          &lt;h:outputText value="Last name: *" /&gt;
                          &lt;p:selectOneRadio id="genderconsole" value="#{staffBean.staff.gender}" required="true"&gt;
                              &lt;f:selectItem itemLabel="Male" itemValue="Male" /&gt;
                              &lt;f:selectItem itemLabel="Female" itemValue="Female" /&gt;
  
                          &lt;/p:selectOneRadio&gt;
                          &lt;p:message for="genderconsole" /&gt;
  
  
                          &lt;p:commandButton value="Create Staff" 
                                           id="ajax" 
  
                                           update="panel"&gt;
  
                          &lt;/p:commandButton&gt;
                      &lt;/h:panelGrid&gt;
                  &lt;/p:panel&gt;
              &lt;/h:form&gt;
          &lt;/f:view&gt;
      &lt;/h:body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This is my StaffBean.java</p>
  
  <pre><code>/*
   * To change this license header, choose License Headers in Project Properties.
   * To change this template file, choose Tools | Templates
   * and open the template in the editor.
   */
  package managedbean;
  
  import entities.Staff;
  import java.io.IOException;
  import java.io.Serializable;
  import java.util.HashSet;
  import java.util.Set;
  import javax.ejb.EJB;
  import javax.enterprise.context.SessionScoped;
  import javax.faces.FacesException;
  import javax.faces.application.FacesMessage;
  import javax.faces.context.ExternalContext;
  import javax.faces.context.FacesContext;
  import javax.faces.view.ViewScoped;
  import javax.inject.Named;
  import sessionBean.staffSessionBeanLocal;
  
  
  @Named(value = "staffBean")
  @SessionScoped
  //@ViewScoped
  public class StaffBean implements Serializable {
  
      @EJB
      private staffSessionBeanLocal staffSession;
      private String userName;
      private String passWord;
      private String loginStatus;
      private Staff staff;
  
  ...........
  ////Code removed
  
      public String getUserName() {
          return userName;
      }
  
      public void setUserName(String userName) {
          this.userName = userName;
      }
  
      public String getPassWord() {
          return passWord;
      }
  
      public void setPassWord(String passWord) {
          this.passWord = passWord;
      }
  
      public String getLoginStatus() {
          return loginStatus;
      }
  
      public void setLoginStatus(String loginStatus) {
          this.loginStatus = loginStatus;
      }
  
      public Staff getStaff() {
          return staff;
      }
  
      public void setStaff(Staff staff) {
          this.staff = staff;
      }
  
  }
  </code></pre>
  
  <p>This is my staff entity.</p>
  
  <pre><code>/*
   * To change this license header, choose License Headers in Project Properties.
   * To change this template file, choose Tools | Templates
   * and open the template in the editor.
   */
  
  package entities;
  
  import java.io.Serializable;
  import java.util.ArrayList;
  import java.util.List;
  import javax.persistence.CascadeType;
  import javax.persistence.Entity;
  import javax.persistence.FetchType;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.ManyToMany;
  
  
  @Entity
  public class Staff extends User implements Serializable {
      private static final long serialVersionUID = 1L;
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Long id;
      private String imageURL;
      @ManyToMany(cascade = {CascadeType.ALL}, fetch = FetchType.EAGER)
      private List&lt;Roles&gt; roles = new ArrayList&lt;Roles&gt;();
  
      @Override
      public Long getId() {
          return id;
      }
  
      @Override
      public void setId(Long id) {
          this.id = id;
      }
  
      @Override
      public int hashCode() {
          int hash = 0;
          hash += (id != null ? id.hashCode() : 0);
          return hash;
      }
  
      @Override
      public boolean equals(Object object) {
          // TODO: Warning - this method won't work in the case the id fields are not set
          if (!(object instanceof Staff)) {
              return false;
          }
          Staff other = (Staff) object;
          if ((this.id == null &amp;&amp; other.id != null) || (this.id != null &amp;&amp; !this.id.equals(other.id))) {
              return false;
          }
          return true;
      }
  
      @Override
      public String toString() {
          return "entities.Staff[ id=" + id + " ]";
      }
  
      public String getImageURL() {
          return imageURL;
      }
  
      public void setImageURL(String imageURL) {
          this.imageURL = imageURL;
      }
  
      public List&lt;Roles&gt; getRoles() {
          return roles;
      }
  
      public void setRoles(List&lt;Roles&gt; roles) {
          this.roles = roles;
      }
  
  }
  </code></pre>
  
  <p>This is my User class which Staff class extends from.</p>
  
  <pre><code>/*
   * To change this license header, choose License Headers in Project Properties.
   * To change this template file, choose Tools | Templates
   * and open the template in the editor.
   */
  
  package entities;
  
  import java.io.Serializable;
  import java.sql.Timestamp;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.MappedSuperclass;
  
  
  @MappedSuperclass
  public class User implements Serializable {
      private static final long serialVersionUID = 1L;
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Long id;
      private String password;
      private Timestamp joinDate;
      private String userType;
      private String gender;
      private String email;
      private String contactNo;
      private String firstName;
      private String lastName;
      private Timestamp dOB;
      private String address;
      private String accountStatus;
      private int numOfFailLogin;
      private String maritalStatus;
      private String activationCode;
  
  
      public Long getId() {
          return id;
      }
  
      public void setId(Long id) {
          this.id = id;
      }
  
      @Override
      public int hashCode() {
          int hash = 0;
          hash += (id != null ? id.hashCode() : 0);
          return hash;
      }
  
      @Override
      public boolean equals(Object object) {
          // TODO: Warning - this method won't work in the case the id fields are not set
          if (!(object instanceof User)) {
              return false;
          }
          User other = (User) object;
          if ((this.id == null &amp;&amp; other.id != null) || (this.id != null &amp;&amp; !this.id.equals(other.id))) {
              return false;
          }
          return true;
      }
  
      @Override
      public String toString() {
          return "entities.User[ id=" + id + " ]";
      }
  
  
      public String getPassword() {
          return password;
      }
  
      public void setPassword(String password) {
          this.password = password;
      }
  
      public Timestamp getJoinDate() {
          return joinDate;
      }
  
      public void setJoinDate(Timestamp joinDate) {
          this.joinDate = joinDate;
      }
  
      public String getUserType() {
          return userType;
      }
  
      public void setUserType(String userType) {
          this.userType = userType;
      }
  
      public String getGender() {
          return gender;
      }
  
      public void setGender(String gender) {
          this.gender = gender;
      }
  
      public String getEmail() {
          return email;
      }
  
      public void setEmail(String email) {
          this.email = email;
      }
  
      public String getContactNo() {
          return contactNo;
      }
  
      public void setContactNo(String contactNo) {
          this.contactNo = contactNo;
      }
  
      public String getFirstName() {
          return firstName;
      }
  
      public void setFirstName(String firstName) {
          this.firstName = firstName;
      }
  
      public String getLastName() {
          return lastName;
      }
  
      public void setLastName(String lastName) {
          this.lastName = lastName;
      }
  
      public Timestamp getdOB() {
          return dOB;
      }
  
      public void setdOB(Timestamp dOB) {
          this.dOB = dOB;
      }
  
      public String getAddress() {
          return address;
      }
  
      public void setAddress(String address) {
          this.address = address;
      }
  
      public String getAccountStatus() {
          return accountStatus;
      }
  
      public void setAccountStatus(String accountStatus) {
          this.accountStatus = accountStatus;
      }
  
      public String getMaritalStatus() {
          return maritalStatus;
      }
  
      public void setMaritalStatus(String maritalStatus) {
          this.maritalStatus = maritalStatus;
      }
  
      public int getNumOfFailLogin() {
          return numOfFailLogin;
      }
  
      public void setNumOfFailLogin(int numOfFailLogin) {
          this.numOfFailLogin = numOfFailLogin;
      }
  
      public String getActivationCode() {
          return activationCode;
      }
  
      public void setActivationCode(String activationCode) {
          this.activationCode = activationCode;
      }
  
  }
  </code></pre>