You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Apache Wiki <wi...@apache.org> on 2005/03/31 10:28:29 UTC

[Struts Wiki] Update of "StrutsMultipleActionForms" by SimonMaticLangford

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Struts Wiki" for change notification.

The following page has been changed by SimonMaticLangford:
http://wiki.apache.org/struts/StrutsMultipleActionForms

------------------------------------------------------------------------------
  
  Dakota Jack
  
+ === Another solution? ===
+ 
+ I have seen another solution, which prevents the need for actions to know about others.
+ 
+ ==== Pre/Post Action ====
+ 
+ It started by using a parameter attribute on the action configuration within struts-config.xml, which has 2 possible values "pre" and "post", these are picked up by a common base class and call two methods, "preExecute" and "postExecute", for each page you define 2 entries in your struts-config:
+ 
+ {{{
+     <!-- Pre action -->
+     <action path="/PrePageA" type="ActionA" name="FormBeanA" parameter="pre">
+       <forward name="Success" path="/pageA.jsp"/>
+     </action>
+ 
+     <!-- Post action -->
+     <action path="/PostPageA" type="ActionA" name="FormBeanA" parameter="post">
+       <forward name="Success" path="/PrePageB.do"/>
+     </action>
+ }}}
+ 
+ The problem with this is that you can pretty much consider your struts-config.xml doubled. I don't claim this one as my own, I think it's quite widely used.
+ 
+ ==== Prepopulate ====
+ 
+ To alleviate the struts-config explosion, this can be approached in another way. Instead of using a parameter to do the switch, do it automatically at page load. If you make a couple of 'tweaks' to the RequestProcessor to make the "processMapping" and "processActionCreate" methods public, and another 'tweak' to the ActionServlet to allow access to the RequestProcessor through an accessor. The html:form knows where it is going to submit, and using these changes can get the action mapping and thus the "Action" that will be invoked when the form is submitted. You can create an interface which defines a prePopulate method, and if your action implements this interface then call it:
+ 
+ {{{
+ ActionMapping mapping = requestProcessor.processMapping(request, response, action);
+ Action action = requestProcessor.processActionCreate(request, response, mapping);
+ 
+ if (action instanceof IPreProcessAction)
+ {
+   IPreProcessAction preProcessAction = (IPreProcessAction) action;
+ 
+   ActionForm actionForm = (ActionForm) pageContext.getAttribute(Constants.BEAN_KEY, PageContext.REQUEST_SCOPE);
+   preProcessAction.preProcess(mapping, actionForm, (HttpServletRequest) request, (HttpServletResponse) response);
+ }
+ }}}
+ 
+ This approach still has problems with passing data from the output of ActionA to the "prePopulate" of ActionB, but with strict session management I still think this provides the best solution at the moment.
+ 
+ Simon Matic Langford
+