Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem when the struts validator rejects user input

 
Roozbeh Ghaffari
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 346
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great ideas guys. Thanks a lot.

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

Roozbeh/
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic