title: Struts2 Usage of RequestAware Interface
body: <p>If my action class is as per below:</p>
  
  <pre><code>&lt;!-- language: lang-java --&gt;
  
  package org.tutorial.struts2.action;
  import java.util.Map;
  import org.apache.struts2.interceptor.RequestAware;
  import org.tutorial.struts2.service.TutorialFinder;
  import com.opensymphony.xwork2.Action;
  
  public class TutorialAction implements Action, RequestAware {
      private String language;
      private String bestTutorialSite;
  
      public String execute() {
          System.out.println(language);
          setBestTutorialSite(new TutorialFinder().getBestTutorialSite(language));
          System.out.println(bestTutorialSite);       
          if (getBestTutorialSite().contains("Java"))
              return SUCCESS;
          else
          return ERROR;
      }
  
      public String getLanguage() {
          return language;
      }
  
      public void setLanguage(String language) {
          this.language = language;
      }
  
      public String getBestTutorialSite() {
          return bestTutorialSite;
      }
  
      public void setBestTutorialSite(String bestTutorialSite) {
          this.bestTutorialSite = bestTutorialSite;
      }
  
      @Override
      public void setRequest(Map&lt;String, Object&gt; requestObj) {
          System.out.println(bestTutorialSite);
          requestObj.put("message", bestTutorialSite);
      }
  
  }
  </code></pre>
  
  <p>When this action is invoked prior to the execute method, the language is already populated by Struts2 framework. In the execute method the <code>setBestTutorialSite</code> method is to populate the private field <code>bestTutorialSite</code>.</p>
  
  <p>Now I thought of setting this private field <code>bestTutorialSite</code> into the request attributes (in the <code>setRequest</code> method). However I notice that this method is invoked first before any private field (like the language) is populated. Hence in the <code>setRequest</code> method, the system print of <code>bestTutorialSite</code> is always null.</p>
  
  <p>I thought I was able to set this attribute with the <code>bestTutorialSite</code> (captured from the execute method) prior to calling the JSP page.</p>
  
  <p>I don't think i fully grasp the understanding of Struts2 flow - obviously! :OP</p>
  
  <p>Please help.
  Thanks.</p>