title: JSF does not populate @Named @RequestScoped bean with submitted input values
body: <p>this is my first question in this beautiful site. I have googled a lot but I didn't find any solution.</p>
  
  <p>I'm new to JSF and I'm learning it with "JSF 2 APIs and JBoss Seam" by Kent Ka lok Tong.</p>
  
  <p>Now I have a problem with a simple login implementation. I have a login page:</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://java.sun.com/jsf/html"&gt;
      &lt;h:head&gt;
          &lt;title&gt;Login&lt;/title&gt;
      &lt;/h:head&gt;
      &lt;h:body&gt;
          &lt;h1&gt;Login&lt;/h1&gt;
          &lt;h:messages for="loginForm" /&gt;
          &lt;h:form id="loginForm"&gt;
              &lt;h:inputText id="username" value="#{loginRequest.username}" required="true" /&gt;
              &lt;h:inputSecret id="password" value="#{loginRequest.password}" required="true" /&gt;
              &lt;h:commandButton value="Login" action="#{loginRequest.doLogin}"&gt;&lt;/h:commandButton&gt;
          &lt;/h:form&gt;
  
      &lt;/h:body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and a backing bean:</p>
  
  <pre><code>package app.controller;
  
  import app.model.beans.User;
  import javax.faces.bean.RequestScoped;
  import javax.inject.Named;
  
  
  @Named("loginRequest")
  @RequestScoped
  public class LoginRequest {
  
      private String username;
      private String password;
  
      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 LoginRequest(){
      System.out.println("created " + this.toString());
      }
  
      public String doLogin(){
  
          if(this.username != null &amp;&amp; this.password != null){
  
              if(this.username.equals("user") &amp;&amp; this.password.equals("password")){
              //this.userHolder.setCurrentUser(username);
              return "success";
  
              }
          return "failure";
  
          }
          return "failure";
  
      }
  
  
  }
  </code></pre>
  
  <p>When I run the application my username and password properties result null. I debugged my app and I saw that setters methods are properly invoked. The problem is that when the setUsername is called there is and instance of the LoginRequest and when it's called the setPassword function the instance is different! Seems that the application do this:</p>
  
  <pre><code>obj1 = new LoginRequest() //username and password = null;
  obj1.username = username;
  
  obj1 = new LoginRequest() //username and password = null;
  obj1.password = password;
  
  obj1 = new LoginRequest() //username and password = null;
  obj1.doLogin();
  </code></pre>
  
  <p>Where I'm in trouble? Where is the mistake?</p>
  
  <p>Thanks a lot!</p>
  
  <p>Best regards</p>
  
  <p>Marco</p>