aspose file tools*
The moose likes Struts and the fly likes Problem when the struts validator rejects user input Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Problem when the struts validator rejects user input" Watch "Problem when the struts validator rejects user input" New topic
Author

Problem when the struts validator rejects user input

Roozbeh Ghaffari
Greenhorn

Joined: Dec 15, 2004
Posts: 2
I have a JSP page that needs to have a few objects set in the request scope in order to render properly. For example my action class loads user's information from database and an object with user info is put in the request (as an attribute). The JSP then uses that object to display user info on parts of the screen.

That JSP happens to have a struts form as well. The problem is if user entered bad input, struts validator rejects the input and then tries to re-render the JSP. But this time my action class is not called before rendering the JSP. So the objects needed to render the JSP do not exist and JSP fails to display properly.

What can I do?

Thanks
Damanjit Kaur
Ranch Hand

Joined: Oct 18, 2004
Posts: 346
I have a JSP page that needs to have a few objects set in the request scope in order to render properly. For example my action class loads user's information from database and an object with user info is put in the request (as an attribute). The JSP then uses that object to display user info on parts of the screen.

That JSP happens to have a struts form as well. The problem is if user entered bad input, struts validator rejects the input and then tries to re-render the JSP. But this time my action class is not called before rendering the JSP. So the objects needed to render the JSP do not exist and JSP fails to display properly.


You can specify the code for getting user info from database in separate bean class( say in its constructor) and initialise all user info with diff. varaibles in Bean class. Then you can specify this Bean in your jsp page with request scope (for e.g. <jsp:useBean id="DBean" scope="request" class="???" /> )
so that whenever jsp page is displayed you will get this user info detail in Bean object and not require to get it from action class.
Sham Grandhe
Ranch Hand

Joined: Dec 16, 2003
Posts: 73
Hi Damanjit Kaur,
This is sham, I too have the same problem. I soon try this way. hope every thing goes well. thank you


sham
Fletcher Estes
Ranch Hand

Joined: Jul 01, 2004
Posts: 108
You can set the input attribute of your ActionMapping to be another Action, rather than a JSP. Whatever Action is called to properly render the JSP, use that as the input of the next Action so that when the validator picks up an error, it immediately re-calls the first Action to put all the necessary data in the request, and properly display the JSP with the error message.
Roozbeh Ghaffari
Greenhorn

Joined: Dec 15, 2004
Posts: 2
Great ideas guys. Thanks a lot.

Using the action as the input worked just fine for me.

Roozbeh/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem when the struts validator rejects user input