In our case, we have chosen to use the java.text.Format as a superclass of
all our validation and formatting classes. I would suggest Struts to
consider this approach. Our decision derives from the following
requirements:
1 Validation of Strings data according to a specified format
The basic requirement is to validate that a string complies to a specified
format. For example, for a string representing a date, the requirement is to
make sure it is of the form: dd/mm/yyyy.
2 Parsing Strings to Objects and vice-versa
Beyond the simple aspect of validating the format of an input string, it is
also often required to transform the validated string into a usable form for
further processing. In Java this means creating an object instance from the
string. With the date example, this could mean creating a java.util.Date
object.
On the other hand, it is also required to perform the reverse operation. In
the case of an instance of a java.util.Date, it should be possible to get a
string representation of it according to a specified format.
3 String buffer parsing and formatting
It should be easy to parse only a certain part of a larger string when the
latter contains the formatting of several elements. Conversely, it should be
easy to append the string representation of an object to an existing string.
This can be useful for example in the context of marshalling object
instances into an XML representation.
4 Independence of the usage context
The classes involved should be coupled to any context of usage. This is to
allow maximum reuse of the logic in various contexts. For example the
framework should not depend on the HTTP request of the Servlet API.
This should enable the creation of a library of formatter that can be used
in various projects. This library can contain basic formatters, but also
more business oriented ones such as account number formatting, etc.
5 Internationalization
In some cases it is necessary to have the parsing and validation processing
aware of locale-specific factors. The date example is again a very good
illustration of this requirement, whereby in the United States dates are of
the form mm/dd/yyyy, while in Europe dates are of the form dd/mm/yyyy. In
the context of a graphical user interface, this is an important requirement.
The java.text.Format class satisfies all the above requirements. It is a
standard Java object, so using it should be consistent with future Java
developments. Finally, J2SE already proposes some formatters for numeric
values, date, and messages.
In our context, these format classes will be used for:
- HTTP request parameter validation
- Handling of request and return buffer to and from legacy systems
- Displaying of the data elements in an HTML front-end
Eventually, beyond the use of Format classes, we intend to create a sort of
format class instance pool, whereby pre-initialized format classes are
stored for repetitive usage. This avoids the creation and initialization of
an object each time a validation/formatting has to be performed. The Struts
digester would be a great tool for initializing this pool.
Comments welcomed!
François Rey
Financial WebSuite
The Capital Markets Company
http://www.capco.com/
-----Original Message-----
From: Ted Husted [mailto:[EMAIL PROTECTED]]
Sent: 06 February 2001 01:01
To: Struts List; [EMAIL PROTECTED]
Subject: Re: Data Validation
On 2/4/2001 at 11:52 PM Neal Kaiser wrote:
>Just wondering... Where do people typically do their validation? In
the
>ActionServlet or ActionForm? Are there any pros/cons?
Validation is still rather controversial. Some people bypass the Struts
mechanism completely.
Typically, you would start by validating the type and range of data in
ActionForm. Once that passes, you might need to do some further
"business logic" validation in the ActionServlet; for example, to check
a login from a database.
*********** REPLY SEPARATOR ***********
>Has anyone thought about adding data validation tags to the Struts
taglibs?
>
>For example, what if we could do:
>
><form:text property="username" required="true"
validationtype="varchar" />
>
>or something like that.
>
>Could it not generate the necessary javascript, as well as provide an
easy
>to use
>interface for detecting and reporting errors in the Action.perform()?
>
>Just wondering... Where do people typically do their validation? In
the
>ActionServlet
>or ActionForm? Are there any pros/cons?
>
>Thanks,
>Neal
-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel 716 425-0252; Fax 716 223-2506.
-- http://www.husted.com/about/struts/
************************************************************************
The information in this email is confidential and is intended solely
for the addressee(s).
Access to this email by anyone else is unauthorised. If you are not
an intended recipient, you must not read, use or disseminate the
information contained in the email.
Any views expressed in this message are those of the individual sender,
except where the sender specifically states them to be the views of
The Capital Markets Company.
http://www.capco.com
***********************************************************************