title: saving login state with static variable - JSF2
body: <p>I like to know whats the correct way to create a login/logout mechanizm in jsf2 environment.
  I have created a login xhtml form and a Admin bean that stores a static boolean (is_authenticated) . I want to check that variable in every xhtml page , if true? continue , else redirect to login page.</p>
  
  <p>this is Admin.java bean: </p>
  
  <pre><code>@ManagedBean
  @SessionScoped
  public class Admin implements Serializable {
  /**
   * 
   */
  private static final long serialVersionUID = 1L;
  static Boolean authenticated;
  String username;
  String password;
  
  @PostConstruct
  public void initialisation() {      // init bean on new instance
      Admin.authenticated = false;
  }
  
  public Boolean getAuthenticated(){
      return Admin.authenticated;
  }
  
  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 doLogout() {
      Admin.authenticated=false;  
  
      return "login?faces-redirect=true";
  }
  
  public String validity() {
  
  
      if(username.equals("admin") &amp;&amp; password.equals("admin")) {
          Admin.authenticated=true;
          return "success";
      }   else   {
          Admin.authenticated=false;
          return "failure";
      }
  }
  
  }
  </code></pre>
  
  <p>and this is the main.xhtml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;ui:composition template="template.xhtml"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:f="http://java.sun.com/jsf/core"      
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:c="http://java.sun.com/jsp/jstl/core"
  xmlns:ui="http://java.sun.com/jsf/facelets"&gt;
  &lt;ui:define name="content"&gt;
  
  &lt;c:if test="#{admin.authenticated == false}"&gt;
  // update Admin.authenticate to false
  &lt;meta http-equiv="refresh" content="0;URL=login.xhtml" /&gt;
  &lt;/c:if&gt;
  
  
  &lt;h1&gt;Statistics&lt;/h1&gt;
  &lt;div style="margin:10px"&gt;
  &lt;h:panelGrid columns="3"&gt;
  Advertisers:
  &lt;h:outputText value="#{stats.advertisers}"/&gt; 
  &lt;h:outputText value=""/&gt;
  Publishers:
  &lt;h:outputText value="#{stats.publishers}"/&gt; 
  &lt;h:outputText value=""/&gt;
  Campaigns:
  &lt;h:outputText value="#{stats.campaigns}"/&gt;
  &lt;h:outputText value="(#{stats.activeCampaigns} active)"/&gt;
  Banners:
  &lt;h:outputText value="#{stats.banners}"/&gt;
  &lt;h:outputText value="(#{stats.activeBanners} active)"/&gt;
  Games:
  &lt;h:outputText value="#{stats.games}"/&gt;
  &lt;h:outputText value="(#{stats.activeGames} active)"/&gt;
  &lt;/h:panelGrid&gt;
  &lt;/div&gt;
  &lt;/ui:define&gt;
  &lt;/ui:composition&gt;
  </code></pre>
  
  <p>Two questions: </p>
  
  <ol>
  <li><p>in the jstl 'if' ,I get :  "Property 'authenticated' not found on
  type com.pkg.name.Admin"</p></li>
  <li><p>How can I update Admin.authenticate to false from the xhtml file(sorry for the lame question, i'm really new to jsf and web dev in general)</p></li>
  <li><p>is it good practice to use this static variable? (like an instance of the session variable)</p></li>
  </ol>