struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bOOyah <boo...@nowhere.org>
Subject Re: How to forward from one LookupDispatchAction to another LDA
Date Fri, 23 Apr 2004 16:34:50 GMT
Riyad Kalla wrote:

<snip />

> Does anyone know how I would be able to forward from one method in an 
> LDA to another method in the same LDA (or any other LDA for that 
> matter...)?

I do exactly this in my own apps.  I use Struts forward Actions in my 
struts-config.  What about something like this? (I'm assuming your 
exsiting Struts forwards and 'showList' method work):

Struts-Config.xml:
=================
     <!-- your main action -->
     <action path="/processMyProducts"
       ...
       <forward name="successShowList" path="/forward/product/showList"/>
       <!-- This might also work, but I don't use it nowadays and
            I cannot remember why:
           <forward name="successShowList"
                    path="/processMyProducts.do?method=showList"/>
       -->
     </action>

     <!-- new, forward Action -->
     <action path="/forward/product/showList"
             parameter="/processMyProducts.do?method=showList"
             type="org.apache.struts.actions.ForwardAction"/>


Your Action class:
=================
public ActionForward execute(/* the usual args */) {
     ActionForward forward = new ActionForward("defaultErrHandler");

     String method= request.getParameter("method");

     if (method!= null && !method.equals("")) {
         if (method.equalsIgnoreCase("showList")) {
             forward = showList(mapping, form, request, response);
         }
         else {
             forward = super.execute(mapping, form, request, response);
         }
     }
     return forward;
}
...
public ActionForward moveDown(/* the usual args */) {
     ...
     // Success! Now refresh the re-ordered list:
     return mapping.FindForward("successShowList");
}

public ActionForward showList(/* the usual args */) {
     // hit the DB for the new list and forward to the JSP
     // etc.
}

To summarise:
(1) The 'moveDown' handler is called.
(2) It looks up "successShowList" thereby forwarding to 
"/forward/product/showList".
(4) "/forward/product/showList" forwards back into your Struts Action 
class with a 'method' parameter called 'showList' causing your existing 
'showList' method to execute.


That's all off the top of my head Riyad.  But I use that approach all 
the time.

-- 
bOOyah


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message