Dmitri, 

I ~really~ like the way this Action works. 

* It keeps control in the Struts-config, and does not embed presentation
details into Action source code. 

* A single mapping could dispatch every HTML form using a given
ActionForm bean. Or, one could choose to use more mappings and fewer
local forwards, as preferred.

* Each local forward can go to a different ActionMapping, or to the same
one with different query strings, or any combination of either approach.

* It is easily adapted for those nasty image buttons and also shows when
they are being used. 

It is similar to a RelayAction that I use quite a bit, but turns things
around. I'd like to adopt it into my "Scaffold" package as
"findForwardAction". (There may be other use-cases beyond buttons that
haven't occurred yet.) Would that be all right? Of course, the author
credit would be yours, and the license is ASF.

-Ted.

Dmitri Valdin wrote:
>
> MultiSubmitAction.java
> ======================
> 
> public class MultiSubmitAction extends Action {
> 
>     public ActionForward perform(ActionMapping mapping,
>                                  ActionForm form,
>                                  HttpServletRequest request,
>                                  HttpServletResponse response)
>         throws IOException, ServletException {
> 
>         String forwards[] = mapping.findForwards();
> 
>         for (int i = 0; i < forwards.length; i++) {
>             if (request.getParameter(forwards[i]) != null) {
>                 // Return the required ActionForward instance
>                 return mapping.findForward(forwards[i]);
>             }
>         }
> 
>         // Go back to input (any other ideas ?)
>         return new ActionForward(mapping.getInput());
> 
>     }
> }
> 
> Some considerations:
> 
> If you never intend to use images, then you can omit ".x" suffix.
> 
> If somebody wants to have all methods stored in one file he can subclass
> DispatchAction
> and play with parameter property:
> 
>     <action    path="/add"
>                type="org.apache.struts.webapp.example.AddDeleteAction"
>                name="testForm"
>               parameter="add"
>               scope="request"
>               input="/test.jsp">
>     </action>
> 
>     <action    path="/delete"
>                type="org.apache.struts.webapp.example.AddDeleteAction"
>                name="testForm"
>               parameter="delete"
>               scope="request"
>               input="/test.jsp">
>     </action>
> 
> Instead of calling return mapping.findForward(forwards[i]) it might be
> interesting to instantiate the action, similar to as it is done in
> ActionServlet
> (protected Action processActionCreate) and just call it's perform() method.
> It would be faster for sure.
> 
> Instead of 'misusing' mappings it might be possible to introduce some
> additional tag
> to action config:
> 
>       <dispatch property="delete.x" path="/delete.do"/>
> or
>       <dispatch property="delete.x" method="delete"/>
> 
> Dmitri Valdin
> 
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel +1 716 737-3463
-- http://www.husted.com/struts/

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to