title: Displaying Validation Error Messages in Struts2
body: <p>I am new to Struts 2, have worked in Struts 1 earlier. </p>
  
  <p>How can we bind a error message with a UI component (e.g. a Text box) ? I don't want the error message to be a global one.</p>
  
  <p>For achieving the same in Struts 1:</p>
  
  <p>In the form validate method, I used this:</p>
  
  <pre><code>ActionErrors errors = new ActionErrors();       
  if(userName != null &amp;&amp; userName.length() &lt;= 0)
      errors.add("userName",new ActionError("error.userName.required"));
  </code></pre>
  
  <p>and in the UI, for displaying the message:</p>
  
  <pre><code>&lt;html:messages id="userName" property="userName"&gt;
      &lt;bean:write name="userName"/&gt;
  &lt;/html:messages&gt;
  </code></pre>
  
  <p>In Struts 2, If I extend the Action  class with <code>ActionSupport</code> and use this:</p>
  
  <pre><code>addActionError(getText("Please enter UserId"));
  </code></pre>
  
  <p>Then it seems to be a global message which can be displayed in the UI using:</p>
  
  <pre><code>&lt;s:actionerror /&gt;
  </code></pre>
  
  <p>Hence not sure how to achieve the same functionality in Struts 2. Kindly let me know on this.</p>