wood burning stoves 2.0*
The moose likes Struts and the fly likes Forward in an action forms reset method. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Forward in an action forms reset method." Watch "Forward in an action forms reset method." New topic
Author

Forward in an action forms reset method.

Patrick McDonogh
Ranch Hand

Joined: Oct 13, 2005
Posts: 89
Hi all,

I am having a spot of bother trying to redirect a request to a specified forward if an exception is thrown in the action forms reset method.

To illustrate i have the following action defined in struts-config.xml.
<action path="/myAction" type="com.my.MyAction"
name="theForm" scope="request" validate="true"
input="input.page">
<forward name="caughtException" path="/caughtError.do"/>
<forward name="success" path="/success.do"/>
</action>

As you can see i have a caughtException forward specified in the action. This is the path i want to forward to if an exception is thrown in the "theForm"'s reset method.
i.e. The forms reset method is shown below.

public void reset(ActionMapping mapping, HttpServletRequest request) {
AnObject o = new AnObject()
try {
o.possibleExceptionMethod();
}
catch (IntegrationException ie) {
ActionForward forward = mapping.findForward("caughtException");
// I now want to forward to this action.
}
}

Does anyone know to forward to the forward which i retrieve in the catch block, that corresponds to this line in the struts-config file? <forward name="caughtException" path="/caughtError.do"/>

Thankyou for your help with the matter and i hope you all have a great day and weekend.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Sorry, Patrcick, you can't do it this way because there's no way to return a forward from an ActionForm.

My suggestion would be to move this logic out of the reset method and into an action class that uses this ActionForm. Then you can forward to another action or JSP if an exception is thrown.


Merrill
Consultant, Sima Solutions
Ravish Ahuja
Greenhorn

Joined: Nov 29, 2004
Posts: 13
You could possibly use RequestDispatcher to forward the request.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Forward in an action forms reset method.
 
Similar Threads
saveToken, isTokenValid, resetToken
Perform() not called in Action class - Struts on Weblogic 6.0
Problem with ActionErrors
deployment errors
LookupDispatchAction - Request does not contain handler parameter name