Sam,
One option for you to look at is the way that the Struts Framework
<http://jakarta.apache.org/struts> deals with this issue -- it is one of the
central organizing principles. Basically, it goes like this:
* You define a "form bean" (an instance of ActionForm) that has properties
matching the fields on your form.
* The form bean has a validate() method, which can be used to return a set
of error messages to the user.
* The controller servlet automatically calls your validate() method and, if any
errors are returned, the user is redirected back to the input page. (If
there
were no errors, the controller servlet would go ahead and call your business
logic action.)
* The input page redisplays, with your error messages and the previously
entered values (so that the user only has to fix what is wrong).
Because Struts uses JSP custom tags heavily, it plays nice with many of the
Taglibs libraries (although there is some overlap in functionality with several
of them). You might want to check it out.
Craig McClanahan
Sam Newman wrote:
> Hi all.
>
> I'm in the process of writing a web application to validate new users
> signing up to a service we provide. What I want to do is to take user input
> via a standard HTML form, validate the information on the client side, and
> if there are any errors redisplay the original page and inform the user of
> the problems. I am currently thinking of the following way to do this:
>
> 1.) Use the input-taglib to construct the form elements to create a form on
> form.jsp.
> 2.) Using the session-taglib, check the session when the form.jsp is
> loaded.If the session contains alternative values for the defaults specfied
> for the form, use them instead.
> 3.) Validation of the form will be carried out using a Servlet.
>
> One problem I have with this is that I'm going to have to pass back
> information to the page if there is an error to tell the user what they
> didn't do correctly. I could simply pass a string in I guess and display
> that in a pre-defined area on the jsp, but ideally I wanted to be able to
> issue an input-by-input report on the problems, and have the error message
> be displayed next to the incorrectly filled out form element. Do you think
> this is feasible?
>
> Does anyone have any comments on this proposed system? Also, any ideas on
> the best way to report errors to the user? I really want to keep the .jsp
> file as simple as possible, so I could easily get a web designer to change
> and edit the pages look and feel - that is I want as little java code as
> possible in the page. Ideally I'd like them to be ableto completely change
> the look of the page without having to touch the non-html stuff.
>
> sam
>
> p.s.
> Having just seen the article on form validation on javaworld, I would like
> to of used that instead, but it doen't allow usage in a commerical product
> :-(