This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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?
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.
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...