• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Problem when the struts validator rejects user input

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great ideas guys. Thanks a lot.

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

Roozbeh/
 
reply
    Bookmark Topic Watch Topic
  • New Topic