You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Lafredo, Stephen" <st...@merck.com> on 2003/06/17 16:08:17 UTC

Action vs. DispatchAction and the input parameter

Hello,

I decided to try a DispatchAction in my application but quickly ran into a
question.

Background:

 As everyone knows, we typically define an Action class as,

  <action path="/foo"
          type="com.action.Foo"
         scope="request"
          name="fooForm"
         input="foo">   <!-- using Tiles -->
    <forward name="success" path="foo-success"/>
  </action>
 
 similarly, we define a DispactionClass as,

  <action path="/bar"
     parameter="method"
          type="com.action.Bar"
         scope="request"
          name="fooBar"
         input="bar">
    <forward name="input"  path="bar"/>
    <forward name="add"    path="add-success"/>
    <forward name="update" path="update-success"/>
  </action>

Question:

 When using an Action class the view specified by the 'input' parameter is
displayed when we invoke the action. For example, http://localhost/foo. Upon
successful completion of the Action we can send the user to the view defined
by the forward element, e.g. foo-success.

 When using a DispatchAction we must specify a parameter identifying the
method we wish to call. For example, http://localhost/bar?method=add. The
problem, I am having is how do I display the DispatchAction's default view
as specified by the 'input' parameter? I want to display this view to
collect information before performing one of the defined actions.

 Unlike an Action class, if I attempt to invoke bar, http://localhost/bar,
w/o specifying a method, reflection fails and an error is displayed.

 I have found two solutions to work around this but they both seem to be
adding more work and confusion to the configuration and I therefore end up
loosing some of the savings gained by using the DispatchAction.

The first solution is to declare another forward element w/in my
DispatchAction declaration to display the form. For example, <forward
name="input" path="bar"/> and then define a NO-OP method in my
DispatchAction class. For example,

   public ActionForward input(ActionMapping mapping
                             ,ActionForm form
                             ,HttpServletRequest request
                             ,HttpServletResponse response)
     throws Exception {

     return mapping.findForward("input");
   }

The second solution is to declare the NO-OP in the struts-config.xml file
and let Struts forward to the view. For example,

    <action path="/bar-input"
         forward="bar"/>

To _me_ these do not seem like optimal solutions.

In the first solution, I am basically re-implementing the functionally
provided to me by Struts in the second solution.

In the second solution, I am adding configurations with confusing naming
conventions to display my input forms w/o invoking my DispatchAction class.

So...

What purpose does the 'input' parameter have when defining a DispatchAction?
None, correct?

Should I only use DispatchActions for GUI(less) actions?

Thanks.

Stephen Lafredo
Merck & Co., Inc.
E: stephen_lafredo@merck.com


------------------------------------------------------------------------------
Notice: This e-mail message, together with any attachments, contains 
information of Merck & Co., Inc. (Whitehouse Station, New Jersey, 
USA) that may be confidential, proprietary copyrighted and/or legally 
privileged, and is intended solely for the use of the individual or entity
named on this message. If you are not the intended recipient, and
have received this message in error, please immediately return this by 
e-mail and then delete it.
------------------------------------------------------------------------------

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