struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Timothy Orme <to...@genome.med.harvard.edu>
Subject Exception Fowarding
Date Wed, 12 Nov 2008 15:23:26 GMT
Hello,

      I have a somewhat complex form for user registration which has several dropdown lists
that pull from a database. I created an action called "RegisterUserFORM" which creates the
dao objects 
necessary for the dropdowns to be made on the JSP page. This form then submits to another
action called "RegisterUser" which handles the business logic of actually registering the
user.

     Here's what I'm trying to achieve:
     1. When the user visits the registration page, we call RegisterUserFORM to provide all
the database objects necessary to render the page.
     2. If the user fills out the form and there is a validation exception, I want the exception
to be caught and redirect the user back to the registration form with the error message on
top.
     3. If the user fills out the form and everything is ok, I want to redirect to a success
page.

Simple enough. The problem I'm having is that I initially tried to have the RegisterUser action
simply redirect to the jsp form page on an exception. However, when I did this I realized
that I would 
have to have all the same getter methods as I did in the RegisterUserFORM action. This seemed
a little unneccsarry and also seemed like a bad idea; I had an action responisble for solely
the jsp level 
elements so why not use it? So instead I tried to have the RegisterUser action redirect to
the RegisterUserFORM action on an error. This solved the initial problem, but created another.
When I 
redirected to the other action, I lost the validation exception that I initially recieved.
The form rendered fine, but now I was missing the error information that was present on it
initially.

So my question then, is whats the best way to handle this? Is there a way to somehow foward
the exception through to the other action? Or is there a better design that I should be using
instead? I can 
think of a couple solutions (such as having both actions extend a class with all the database
elements necessary for the form) but none seem very "elegant". Does anyone have a better solution?

Thanks,
Tim Orme

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


Mime
View raw message