title: Sessionscoped managed bean not saving variables jsf
body: <p>I have a bit strange problem with a managed session scoped bean. I am quite new to jsf and this is looking strange. The case is:
  loginBean stores some variables that are initialized after a successful login. At first time, they are initialized, but after the successful login, the user is redirected to a profile.xhtml page, in which I call these variables from loginBean. In this page the variables from the loginBean are null. So I lose all the data after redirection.</p>
  
  <p>loginBean:</p>
  
  <pre><code>package beans;
  
  import facades.ContactFacade;
  import facades.UsersFacade;
  import java.io.Serializable;
  import javax.ejb.EJB;
  import javax.faces.bean.ManagedBean;
  import javax.faces.bean.SessionScoped;
  import model.Contact;
  
  @ManagedBean(name="loginBean")
  @SessionScoped
  
  public class LoginBean implements Serializable{
      @EJB
      private ContactFacade contactFacade;
      @EJB
      private UsersFacade usersFacade;
  
  private String Name;
  private String Password;
  private int ContactID;
  private Contact contact;
  
  public LoginBean() {
  
  }
  
  public Contact getContact() {
      return contact;
  }
  
  public void setContact(Contact contact) {
      this.contact = contact;
  }
  public String getName() {
      return Name;
  }
  
  public void setName(String Name) {
      this.Name = Name;
  }
  
  public String getPassword() {
      return Password;
  }
  
  public void setPassword(String Password) {
      this.Password = Password;
  }
  public int getContactID() {
      return ContactID;
  }
  
  public void setContactID(int ContactID) {
      this.ContactID = ContactID;
  }
  
  private boolean checkValidity(){
      return (
              (getName()!=null&amp;&amp;getName().length()&gt;0)
              &amp;&amp;(getPassword()!=null&amp;&amp;getPassword().length()&gt;0))
              ?true:false;
  }
  public String login(){
      if(checkValidity()&amp;&amp;usersFacade.tryLogin(getName(), getPassword())){
          setContactID(usersFacade.getContactID(getName()));
  
          getContactInstance();
          return "profile.xhtml?faces-redirect=true";
      }else{
          return "loginError.xhtml?faces-redirect=true";
      }
  }
  
  private void getContactInstance(){
      setContact(contact);
      this.contact=contactFacade.getContact(getContactID());
  } 
  
  public String getDepartment(){
      return contactFacade.getDepartmentName(getContact().getDepartment());
  }
  }
  </code></pre>
  
  <p>profile.xhtml jsf</p>
  
  <pre><code>&lt;h:form&gt;
          &lt;h2&gt;My information&lt;/h2&gt;
          &lt;h:panelGrid columns="2"&gt;
              &lt;h:outputLabel value="Name:"/&gt;
              &lt;h:outputLabel value="#{loginBean.contact.name}"/&gt;
  
              &lt;h:outputLabel value="Lastname:"/&gt;
              &lt;h:outputLabel value="#{loginBean.contact.lastname}"/&gt;
  
              &lt;h:outputLabel value="Address:"/&gt;
              &lt;h:outputLabel value="#{loginBean.contact.address}"/&gt;
  
              &lt;h:outputLabel value="Telephone:"/&gt;
              &lt;h:outputLabel value="#{loginBean.contact.telephone}"/&gt;
  
              &lt;h:outputLabel value="Email:"/&gt;
              &lt;h:outputLabel value="#{loginBean.contact.email}"/&gt;
  
              &lt;h:outputLabel value="Department:"/&gt;
              &lt;h:outputLabel value="#{loginBean.department}"/&gt;
  
              &lt;h:commandButton id="btnChange" value="Change Info" /&gt;
  
  
          &lt;/h:panelGrid&gt;
  
      &lt;/h:form&gt;
  </code></pre>
  
  <p>This is quite strange for me. Can anyone help? Thanks in advance</p>