Many times pre-processing and post-processing are related, and it can be
convenient to handle both in the same Action class. 

A good way to implement this is to have a seperate Action Mapping for
each task (pre-process and post-process). Both mappings would point to
the same Action but use different (virtual) paths. Like say <
/account/setup/pre > and < /account/setup/post >. These may both use the
same Action class, which could be < package/account/setup.java >. 

The Struts mappings accept an extra "parameter" property that you can
easily test in the Action to see which mapping has been chosen. Your
action can
then process each task differently, and even go to separate locations if
successfuly. By managing this all in the struts-config.xml, you gain a
lot of flexbility. 

In struts-config: 

<action 
  path="/account/setup/pre"
  type="package.account.Setup.java"
  name="setupForm"
  scope="request"
  validate="false"
  input="/WEB-INF/jsp/account/setup/Form.jsp"
  parameter="pre">
  <forward 
    name="success"  
    path="/WEB-INF/jsp/account/setup/Form.jsp"/>
</action>

<action 
  path="/account/setup/post"
  type="package.account.Setup.java"
  name="setupForm"
  scope="request"
  validate="true"
  input="/WEB-INF/jsp/setup/Form.jsp"
  parameter="post">
  <forward 
    name="success"  
    path="/WEB-INF/jsp/account/setup/View.jsp"/>
</action>

In your Action: 

  String task = mapping.getParameter();
  // handle task for "pre" or task for "post"
  // ...
  // ...
  return (mapping.findForward("success"));

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


Kiet Nguyen wrote:
> 
> I need to pre-populate my form and do some business processes prior to load
> a page.  Where would be the best place for this.  I don't want to put it in
> the peform method of the "from page".  And doing business process at the
> form bean does not seen appropriate.

Reply via email to