title: Struts 2 - Set bean on action
body: <p>I'm trying to set a simple bean through a form with Struts 2 actions. I'm quite new with this framework, and I don't see what I'm missing...</p>
  
  <p>The bean <code>FormBean</code>:</p>
  
  <pre><code>public class FormBean {
      private String login="";
      private String password="";
  
      public String getLogin() {
          return login;
      }
      public void setLogin(String login) {
          this.login = login;
      }
      public String getPassword() {
          return password;
      }
      public void setPassword(String password) {
          this.password = password;
      }   
  }
  </code></pre>
  
  <p>The action <code>FormAction</code>:</p>
  
  <pre><code>public class FormAction extends ActionSupport {
  
      private FormBean form;  
  
      @Override
      public String execute() throws Exception {
          return SUCCESS;
      }
  
      public FormBean getForm() {
          return form;
      }    
      public void setForm(FormBean form) {
          this.form = form;
      }
  }
  </code></pre>
  
  <p>The form <code>index.jsp</code>:</p>
  
  <pre><code>&lt;%@ page contentType="text/html; charset=UTF-8"%&gt;
  &lt;%@ taglib prefix="s" uri="/struts-tags"%&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;/head&gt; 
  &lt;body&gt;
  &lt;s:form action="login.action" method="post"&gt;
      &lt;s:textfield name="form.login" label="User" size="20" /&gt;
      &lt;s:password name="form.password" label="Password" size="20" /&gt;
      &lt;s:submit method="execute" value="Login" align="center" /&gt;
  &lt;/s:form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The result <code>Welcome.jsp</code>:</p>
  
  <pre><code>&lt;%@ page contentType="text/html; charset=UTF-8"%&gt;
  &lt;%@ taglib prefix="s" uri="/struts-tags"%&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;h2&gt;Welcome &lt;s:property value="form.login" /&gt;&lt;/h2&gt;
      &lt;p&gt;&lt;s:property value="form.password" /&gt;&lt;/p&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>When I submit the form, my data isn't displayed and I get this exeption :</p>
  
  <pre><code>Unexpected Exception caught setting 'login' on 'class tuto.form.FormAction: Error setting expression 'login' with value ['test', ]
  Error setting expression 'login' with value ['test', ] - [unknown location]
      at com.opensymphony.xwork2.ognl.OgnlValueStack.handleRuntimeException(OgnlValueStack.java:197)
  [...]
  Caused by: No object in the CompoundRoot has a publicly accessible property named 'login' (no setter could be found). - [unknown location]
      at com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor.setProperty(CompoundRootAccessor.java:106)
  [...]
  </code></pre>