• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Forward in an action forms reset method.

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could possibly use RequestDispatcher to forward the request.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic