struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject RE: How to add a pre-action
Date Mon, 21 Oct 2002 15:25:38 GMT

We use pre-actions for all of our pages.
I too would like more examples of this type of thing.
I can't say if this is the best way or not, but we are in mid construction
of out first Struts app and have have found that certain situations keep

Most of our pages look like the Master- detail style.  most actions (like
refresh, add,delete, sort..) all refresh the same page with some result or

The actions are coded so that they do not know who is calling them, but
they do need to know or handle  certaing things about the state of the
ie: If the page is loaded for the first time, I have to set defaults
Each page has one or more forms and a dynamic list of records.

If we let struts validate, then the input is set to the loadAction instead
of the page

Here is a condensed hunk of code from our loadAction:

I create one form bean manually for a summary section  but
for the main form  on the page I use the mapped form bean from my action
mapping (it gets passed into the action).

<form-bean name="customerInquiryForm" type=""/>

<action path="/inquiryLoad"
     <forward name="success" path="/WEB-INF/customer/CustomerInquiryPage.jsp" />

// A Page Action
     <forward name="success" path="/" />


public class CustomerInquiryLoadAction extends ArAuthenticatedAction {

    static Logger log = Logger.getLogger(CustomerInquiryLoadAction.class.getName());

    public ActionForward executeAction(ActionMapping mapping,ActionForm form,
    HttpServletRequest request,HttpServletResponse response,
    ArService service) throws Exception{
        if(log.isDebugEnabled()) log.debug(" ** Start ** ");
        ActionErrors errors = new ActionErrors();
        ActionMessages messages = new ActionMessages();
        HttpSession session = request.getSession();

         //set the  customer summary form into scope
        CustomerDetailsVO custDetails = service.getCustomerDetails();
        CurrentCustomerForm currCustForm = new CurrentCustomerForm(custDetails);

            //Main form on page
        CustomerInquiryForm inqForm = (CustomerInquiryForm)form;
        if(log.isDebugEnabled()) log.debug("FORM: " + inqForm);
        //default parameter values if entering the page for the first time
        if(inqForm.getItemStatusType() == null ) inqForm.setItemStatusType(WebConstants.ZERO);
        if(inqForm.getTransactionType() == null) inqForm.setTransactionType(WebConstants.ZERO);

        //get the list from backend service
        List txList = service.getCustomerTxnList(WebUtil.stringToInt(inqForm.getTransactionType()),WebUtil.stringToInt(inqForm.getItemStatusType()));
        service.sortList(txList, inqForm.getInqSortColumn(), inqForm.getInqSortOrder());

            //set the main list in th eform bean

            //Get mainlist form backend service
        SessionList detailItemList = service.getDetailItemList(WebUtil.stringToInt(inqForm.getTransactionType()));

        return (mapping.findForward(WebConstants.MAPPING_SUCCESS));


"Chappell, Simon P" <> on 10/21/2002 09:42:56 AM

Please respond to "Struts Users Mailing List"

To:    "Struts Users Mailing List" <>,

Subject:    RE: How to add a pre-action

Remember that the Struts example application, while it does work, is
perhaps best considered as a bad example. If I ever get any free time, I'd
love to re-write it with some of the best practices that are now being
discovered. Don't anyone hold their breath though. :-(


Simon P. Chappell           
Java Programming Specialist            
Lands' End, Inc.                                   (608) 935-4526

>-----Original Message-----
>From: Howard Miller []
>Sent: Sunday, October 20, 2002 10:56 AM
>To: Struts Users Mailing List
>Subject: Re: How to add a pre-action
>I think I'm seriously missing the point here! I have looked at
>the example application
>in some detail and it appears to add a parameter (eg,
>?action=new) to tell the action
>for a form to perform an initialising action. I don't see it
>using a "pre-" action.
>I am incredibly stuck with the concept of how to code an
>action that is not
>encumbered with *special* parameters to pre-load the bean
>data. My particular
>problem is that I have pages where the previous page cannot be
>predicted, so the jsp
>must have a means of loading its own data.
>I would really appreciated some pointers as to how to set this
>up. *** I particularly
>don't understand how to get the action to call the following
>JSP *** (ie, I would really
>appreciate some specific - example - help on this!! ). At
>least every method I have
>tried doesn't work.
>I do understand how to actually create a bean manually and put
>in in the scope. I
>don't understand how to set up a generic preload action for a
>given JSP/ActionForm,
>and what the config should look like.
>Again, any help much appreciated.
>On 20 Oct 2002 at 8:43, David M. Karr wrote:
>> >>>>> "Howard" == Howard Miller <> writes:
>>     Howard> Hi,
>>     Howard> Can somebody kindly help me with the following...
>>     Howard> I want to add a path and an Action class. The
>action class will then preload data into
>>     Howard> a bean and then forward (do I mean forward) to
>the jsp that displays the bean. That's
>>     Howard> it. I want this action to be in *addition* to
>the *normal* jsp/formbean/action setup.
>>     Howard> I can't see how to do it.... in particular
>>     Howard> 1. I don't think I fully understand how/why an
>action is associated with a bean in
>>     Howard> struts-config. What does the action servlet do
>with this information.
>>     Howard> 2. How do I properly forward from an action to a
>jsp with the bean information intact.
>>     Howard> It seems to be very similar to an action
>returning its "input form" to display errors, but
>>     Howard> doing this doesn't work.  Whatever I do I seem
>to get a blank page.
>> In fact, the best practice is to always preface a page with
>an action.  You end
>> up with actions that prepare information for a page, and
>actions which process
>> information for a page.  The actions which process the page
>information will
>> always have had the form bean created before you get to the
>action.  However,
>> the actions which prepare the page information may have to
>manually create the
>> form bean and put it into the appropriate scope.
>> Note that the welcome page for an application would normally
>be something like
>> "index.jsp", which does nothing but forward to an action to start the
>> application.  You can't preface the welcome page with an
>action, but you can
>> make it do nothing but go to an action to prepare the real
>first page.
>> Look at the source code for the "example" application for
>some examples of
>> using the form bean.  The user guide also talks about the
>control flow with
>> respect to form beans.
>> --
>> ===================================================================
>> David M. Karr          ; Java/J2EE/XML/Unix/C++
>> --
>> To unsubscribe, e-mail:
>> For
>additional commands,
>e-mail: <>
>To unsubscribe, e-mail:
>additional commands,
>e-mail: <>

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message