Hi Edward, 

 

Create a method for handling "all the rest" or unspecified actions, and
delegate to your view:

 

protected ActionForward unspecified(ActionMapping mapping, ActionForm
form,

                                    HttpServletRequest request,
HttpServletResponse response)

                                    throws Exception {

 

                        return getView(mapping, form, request,
response);

            }

MG

________________________________

From: Edward Song [mailto:[EMAIL PROTECTED] 
Sent: Thursday, March 06, 2008 3:04 PM
To: 'Struts Users Mailing List'
Subject: DispatchAction nonexisting method

 

Hi all,

 

First, this is not a Struts 2 question....

And thanks to anyone who reads below...

 

I was wondering how other's handled this problem with the
org.apache.struts.actions.DispatchAction in Struts 1.3.9.

 

I have an action that calls a data service that is to be presented to
the user in numerous formats by using DispatchAction.  

*       View
*       XLS
*       PDF

 

As they all utilizes a common data service, I thought that this would be
an excellent candidate for DispatchAction to centralize the call into
one action.

Say the parameter used was named "export", so my action mapping looks
like,

 

<action path="/UserOrders"
type="com.nuhorizons.web.shop.actions.UserOrders" scope="request"
parameter="export">

      <forward name="success"
path="/WEB-INF/jsps/pages/userOrders.jsp"/>

</action>

 

UserOrders extends DispatchAction and all this is working fine.

 

I implement the following methods.

 

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

 

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

 

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

 

All is well, until.......

http://localhost:8080/myapp/UserOrders.do?export=unnamedmethod

 

 

When DispatchAction attempts to find the unnamedmethod, it throws a
NoSuchMethodException prior to calling any method.  Our app is
configured to show a 500 page, and I know that I could use the
<global-exceptions> and create an exception handler but the
NoSuchMethodException is such a generic exception.  Wrapping the
exception is not really an option as it is thrown by DispatchAction. 

 

Has anyone thought of a good way for DispatchAction to handle an unnamed
method??  

 

Ed

Reply via email to