File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Redisplay form data and error messages in JSP after validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Redisplay form data and error messages in JSP after validation" Watch "Redisplay form data and error messages in JSP after validation" New topic
Author

Redisplay form data and error messages in JSP after validation

Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

Hi,

i'd like to know how do you handle data validation/correction in JSP!

My plan is to get user data from a HTML form in a Java bean and after some validation within the bean i set up a corresponding bean with error messages appropriate for the particular HTML form.

If there are errors i could redisplay the same JSP and for each form field i could test if there's an error message set in my error bean (with EL or JSTL tags) and decide with <c:if> for example to display additional hints on how to correct data in a form field.

What do you recommend for showing validation results in a JSP? Is my idea with two beans, one for user data and for error messages, a reasonable way to go or is there perhaps an easier or better way?

Thanks for your answers!

Marco
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30130
    
150

Marco,
I like the approach of keeping the error messages in a separate object because it is easy to check if there are any - just see if the object is in the request. As a point of interest, some frameworks (like Struts) do it this way too.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

Ok, now i'm relieved. If Struts is doing it that way i can't be too bad

From an architectural point of view would it be bad design to create the error bean directly from within a validate() method of my form data bean? I'm new to this topic and unsure if my ideas are reasonable. Although at the moment i see no other possibility without making things more complicated than really necessary...
 
 
subject: Redisplay form data and error messages in JSP after validation
 
Similar Threads
User data disappears after validation routine
Reset button & Validation Error
Problem with jquery.validate.js plugin selectors
validate()
Struts - validate()