struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ted Husted" <hus...@apache.org>
Subject Re: Manually obtain previous action parameters after action "chaining"?
Date Thu, 11 Oct 2007 12:26:48 GMT
The Action itself is not copied over, the PROPERTIES are copied. If
the properties in common are copied forward, then there should be no
need to address the prior Action class directly. Any methods that need
to be called by more than one Action should be moved to a base support
class that the Actions can share.

Also, there is rarely a need to use HTTP semantic in a Struts 2
Action. The SessionAware and RequestAware interceptors expose the
session and request attributes as entries in Maps. request.getSession
doesn't work, because the interceptor doesn't pass the HttpRequest
object but a map the proxies the attributes in request scope. If the
Action needs access to the session attributes, then implement
setSession(Map).

-Ted.


On 10/11/07, Igor Vlasov <vigor78@mail.ru> wrote:
>
> 1. I have "actionOne"
>
> public class ActionOne extends ActionSupport implements ServletRequestAware{
>   protected HttpServletRequest request;
>
>   private SearchParameter searchData=new SearchParameter();//My complex
> object
>
>   public String execute() throws Exception{
>      //fill searchData with parameters. Many many parameters.....
>       return this.SUCCESS;
>   }
>
>   // this is for ability to copy object searchData to next chain action
>   public SearchParameter getSearchData() {
>     return searchData;
>   }
>
>   public void setServletRequest(HttpServletRequest httpServletRequest) {
>     request = httpServletRequest;
>   }
>
> }
>
> 2.
>   <package name="searchEngine" namespace="/s2examples"
> extends="struts-default">
>     <action name="*search" class="s2.action.ActionOne" method="{1}"  >
>       <result  name="success" type="chain" >doSearch</result><!--to search
> -->
>       <result  name="input" >search.jsp</result> <!--input -->
>     </action>
>     <!-- специально сделана отдельно, чтобы на нее
наложить execAndWait -->
>     <action name="doSearch" class="s2.action.ActionTwo"  >
>       <interceptor-ref name="completeStack"/>
>       <interceptor-ref name="execAndWait">
>         2000
>         500
>       </interceptor-ref>
>       <result  name="wait">wait_search.jsp</result>
>       <result  name="success" type="redirect"  >search_result.jsp</result>
>     </action>
>   </package>
>
> 3.
> public class ActionTwo  extends ActionSupport implements ServletRequestAware
> {
>   protected HttpServletRequest request;
>   private SearchParameter searchData;
>   private HttpSession sess;
>   public String execute() throws Exception{
>      sess = request.getSession();
>      boolean v =(searchData!=null);// ok. we recieve a copy of searchData
> from previos action
>      try {  Thread.currentThread().sleep(6*1000);  } catch
> (InterruptedException ex) {}
>      sess = request.getSession(); // return null object!!! why ?
>      return this.SUCCESS;
>   }
>   /*this work and  searchData object has been copied from previos action */
>   public void setSearchData(SearchParameter searchData) {
>     this.searchData = searchData;
>   }
> }
>
> The desired behaviour:
>
> public class ActionTwo  extends ActionSupport implements ServletRequestAware
> {
>   protected HttpServletRequest request;
>   private HttpSession sess;
>   public String execute() throws Exception{
>      SearchParameter searchData=null;
>      try {  Thread.currentThread().sleep(6*1000);  } catch
> (InterruptedException ex) {}
>      //!!!!
>       ActionOne prev=null;
>       prev=(ActionOne)getPreviousAction();
>       searchData=prev.getSearchData();
>      //!!!!
>      sess = request.getSession(); // return null object!!! why ?
>      return this.SUCCESS;
>   }
>
> }
> ===============================================================
> for simplisity simplicity searchData may be a simple Object().
> I need an ability to make : prev=(ActionOne)getPreviousAction();
Mime
View raw message