I'm writing a "Model 1" web application right now with custom tag libraries
that requires form input validation. I'm not using scriptlets in my JSP's
nor JavaScript--only custom taglibs. 

I'm using the Request taglib to test the GET/POST query string for parameter
availability, and the Regexp taglib to test for text pattern matching. So
far that's all I've needed. The Session taglib comes in very handy for
temporarily storing values for control/testing and retaining values between
JSP pages.

These same taglibs allow me to provide user feedback in the form as well as
provide error notices. My pages are constructed so that banners, menus, and
status/error messages are included at the top of every page. When the JSP
determines there is an error with a form field, it sets a session attribute
named Error, as well as a specific session attribute for the error in that
field. A page called status.jsp is included at the top of every page--it
evaluates whether there is an error or status session attribute, displays it
appropriately below the banner and menu, and then clears the error session
attribute for the next round of validation (if needed). When the form is
built, individual session attributes are tested to see if a specific error
occurred in the form. If an error occurred, I mark the field with a visual
indicator and then clear the session attribute. When an error occurs, what
the user entered in the form is automatically added back into the form by
using the request parameters in the values of the form fields.

The Request, Session, and Regexp taglibs make this very easy. Check them
out. 

Good luck with your project. 

Regards,
Garrel Renick
[EMAIL PROTECTED]


-----Original Message-----
From: Sam Newman [mailto:[EMAIL PROTECTED]]
Sent: Monday, April 30, 2001 9:04 AM
To: [EMAIL PROTECTED]
Subject: Form validation


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
:-(

Reply via email to