struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ted Husted <>
Subject Re: Datetime validation taglib for struts?
Date Fri, 15 Feb 2002 13:58:59 GMT
The domain-type validations, like whether it is a date, can be handled
in the ActionForm validate, if that's helpful. The Struts Validator is
very good for this, and keeps everything out in an XML file where it can
be easier reviewed. Range checks that depend on the model state would
still have to be performed in the action, though. 

A lot of it depends on what you already got. If the model beans already
do the validation, let them. If they don't, do what you can in the

Transformations are trickier. I don't have a really good solution for
transforming binary data. There are some tools, like Rey Francois'
mapper, but I haven't put them into a production app myself. 

For properties representing formatted binary data, I tend to have
getDate (binary) and getDateText (string) properties. 

The action sets the binary property, which in turn also sets the String
field. The form sets the String property (property="dateText"), which
also tries to convert it into a binary. 

If it fails, the binary field goes to null, but all exceptions are
caught. Otherwise, it updates the binary field. 

The validator can then look at whether dateText and/or date are empty,
and post the appropriate validation error (if any). 

The methods in question rely on static methods in a utility class, to
eliminate as much unique code from the action form bean as possible. 

When the form gets to the action, the model bean can get it's value from
the binary property. 

Since I tend to use reflection for this, I use the "real" property name
for the binary version, and append "Text" for the "formatted for
display" version. The same approach can be used for String fields like
telephone numbers, where you might want to store only the digits,
without any punctuation. The telephoneText property copes with hyphens
and spaces. The telephone property is a string with all digits.

This is probably the most common approach right now, but it's a pain to
setup. It also means that properties are sharing fields, or else you at
least need a setDateTextRaw() property to avoid looping. 

A transformation plugin to the Validator that could be configured with
XML would be much better. 

-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Java Web Development with Struts.
-- Tel +1 585 737-3463.
-- Web wrote:
> Thanks Mark for your answer.
> I was just curious how most others here choose "when" to perform things
> like date/numeric validation?
> thanks,
> Therion
>                     Mark Woon
>                     <morpheus@SMI.Sta        To:     Struts Users Mailing List <>
>                     nford.EDU>               cc:
>                                              Subject:     Re: Datetime validation taglib
for struts?
>                     02/14/02 02:24 PM
>                     Please respond to
>                     Struts Users
>                     Mailing List
> wrote:
> > Does there exist a taglib or a way to perform date/time validation on an
> > input form WITHOUT having to use Javascript in the form?
> [snip]
> > I don't see any that will actually perform validation on a field after
> > focus has been lost...
> I don't see how you could possibly perform client-side validation ("after
> focus
> has been lost") without using Javascript...
> -Mark
> --
> To unsubscribe, e-mail:   <
> For additional commands, e-mail: <
> --
> To unsubscribe, e-mail:   <>
> For additional commands, e-mail: <>

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message