struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff_Mycha...@nlgroup.ca
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
appearing.

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
message.

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
page.
ie: If the page is loaded for the first time, I have to set defaults
ects...
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
input="/inquiryLoad.do"



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).

//Config
<form-bean name="customerInquiryForm" type="com.nlg.ar.web.customer.form.CustomerInquiryForm"/>

<action path="/inquiryLoad"
        name="customerInquiryForm"
        type="com.nlg.ar.web.customer.action.CustomerInquiryLoadAction"
        scope="request"
        validate="false">
     <forward name="success" path="/WEB-INF/customer/CustomerInquiryPage.jsp" />
  </action>

// A Page Action
 <action
      path="/inquiryRefresh"
      type="com.nlg.ar.web.common.action.GlobalRefreshAction"
      name="customerInquiryForm"
      scope="request"
      validate="false">
     <forward name="success" path="/inquiryLoad.do" />
  </action>

//Code....

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);
        request.setAttribute(WebConstants.FORM_NAME_CURRENT_CUSTOMER,currCustForm);
        //


            //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
        inqForm.setPageList(txList);

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

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

}




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

Please respond to "Struts Users Mailing List"
       <struts-user@jakarta.apache.org>

To:    "Struts Users Mailing List" <struts-user@jakarta.apache.org>,
       <me@howardmiller.co.uk>
cc:

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

-----------------------------------------------------------------
Simon P. Chappell                     simon.chappell@landsend.com
Java Programming Specialist                      www.landsend.com
Lands' End, Inc.                                   (608) 935-4526


>-----Original Message-----
>From: Howard Miller [mailto:me@howardmiller.co.uk]
>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.
>
>HM
>
>On 20 Oct 2002 at 8:43, David M. Karr wrote:
>
>> >>>>> "Howard" == Howard Miller <me@howardmiller.co.uk> 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++
>> dmkarr@earthlink.net
>>
>>
>> --
>> To unsubscribe, e-mail:
><mailto:struts-user->unsubscribe@jakarta.apache.org>
>> For
>additional commands,
>e-mail: <mailto:struts-user-help@jakarta.apache.org>
>>
>>
>
>
>
>--
>To unsubscribe, e-mail:
><mailto:struts-user->unsubscribe@jakarta.apache.org>
>For
>additional commands,
>e-mail: <mailto:struts-user-help@jakarta.apache.org>
>
>

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








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


Mime
View raw message