File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Redirecting to the JSP when validation error occurs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Redirecting to the JSP when validation error occurs" Watch "Redirecting to the JSP when validation error occurs" New topic

Redirecting to the JSP when validation error occurs

Srilakshmi Vara
Ranch Hand

Joined: Jul 21, 2004
Posts: 169
Hello All,

Thanks for your suggestions before.

Have another question!

I am populated a page using some database values, if user enters some values upon that and submits the form i am redirecting to .do(which populates with DB values) but i am loosing user entered values, if i redirect to the jsp i am getting null pointer exception on populated field values.

What to do in this scenario?

Thanks in advance,
alan do
Ranch Hand

Joined: Apr 14, 2005
Posts: 354
create a 3rd action mapping that is mapped to the same form-bean definition and used this new mapping (uri) as your 'input' attribute for the action where you set validation to true. in essense, you'll have 3 mappings (a bit ugly, yes):

1. /myaction/ (name="MyForm") //where DB values are loaded initially

2. /myaction/ (name="MyForm" validate="true" input="/myaction/") //where action is submited to

3. /myaction/ (name="MyForm") //temporary uri to hold form values, needs to map this to a different action class that forwards to the same jsp/tile as #1 mapping.

this is a little easier if you have all 3 inside a DispatchAction. the only thing you'll have to do is create a 'failed' method in the DispatchAction and specify the param attribute's value to 'failed' for the input (input="/myaction/").
[ May 16, 2005: Message edited by: alan do ]

-/a<br />certified slacker...yes, my last name is 'do' - <a href="" target="_blank" rel="nofollow"></a>
I agree. Here's the link:
subject: Redirecting to the JSP when validation error occurs
It's not a secret anymore!