I should have read more carefully, that is trickier. It looks like you 
could override getMethod, attempt to execute super.getMethod, trap 
the NoSuchMethodException if the method is not found, and return 
a Method corresponding to unspecified:

Method method = null;
try {
 method = super.getMethod(name);
}
catch (NoSuchMethodException e) {
 method = super.getMethod("unspecified");
}
return method;

I know that it is less than ideal to have to catch the Exception to 
determine if the method is missing or not, but hopefully that will 
not occur very often...

-----Original Message-----
From: Larry Zappeterrini 
Sent: Monday, February 03, 2003 3:10 PM
To: 'Struts Users Mailing List'
Subject: RE: how to handle method not found in DispatchAction


You should override the method unspecified. Check out the 
DispatchAction Java doc:

http://jakarta.apache.org/struts/api/org/apache/struts/actions/DispatchActio
n.html#unspecified(org.apache.struts.action.ActionMapping,%20org.apache.stru
ts.action.ActionForm,%20javax.servlet.http.HttpServletRequest,%20javax.servl
et.http.HttpServletResponse)

-----Original Message-----
From: Wendy Smoak [mailto:[EMAIL PROTECTED]]
Sent: Monday, February 03, 2003 3:05 PM
To: 'Struts Users Mailing List'
Subject: RE: how to handle method not found in DispatchAction


> suppose I have a following URL
> /pages/MyDispatchAction.do?nextpage=home
> and class MyDispatchAction has a method
> public ActionForward home(...)
> so this request is handled by this method,
> Suppose there is a request to DispatchAction , for
> which there is no method to handle it , it crashes, 
> Is there a way to forward all these request to a
> default page, if there is no method to handle the
> request???
> Has anyone written or done some thing like this to
> handle this error neatly

I override execute() and provide a default, but my main problem is the
action being called *without* the parameter, not with one that doesn't have
a mapping.

public final class EditContactAction extends LookupDispatchAction
{

   public ActionForward execute( ... )
   {
      if ( request.getParameter( mapping.getParameter() ) == null ) {
         log.debug( "parameter is missing, defaulting to add" );
         return addContact( mapping, form, request, response );
      } else {
         log.debug( "parameter present, calling super.execute" );
         return super.execute( mapping, form, request, response );
      }

   }
}

Sounds like you would need to do something like:
  if ( !getKeyMethodMap.containsKey( request.getParameter(
mapping.getParameter() ) ) { ... }

(But my getKeyMethodMap creates a new Map every time, and I wouldn't want to
do that... perhaps the Map should be a class variable instead.)

Personally I would like to see a 'default' attribute for the <action> tag.
That way LookupDispatchAction could itself fall back on a default value if
the specified parameter is missing or not in the Map.

-- 
Wendy Smoak
Applications Systems Analyst, Sr.
Arizona State University PA Information Resources Management


*************************************************************************** 
This electronic mail transmission contains confidential and/or privileged 
information intended only for the person(s) named.  Any use, distribution, 
copying or disclosure by another person is strictly prohibited. 
*************************************************************************** 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


*************************************************************************** 
This electronic mail transmission contains confidential and/or privileged 
information intended only for the person(s) named.  Any use, distribution, 
copying or disclosure by another person is strictly prohibited. 
*************************************************************************** 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to