struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Patrick Refondini <>
Subject Re: Datetime validation taglib for struts?
Date Sat, 16 Feb 2002 14:44:56 GMT
Transformation mechanism for binary data, taking the date example.

Trying to deal with java.util.Date in Struts I have came to look for :

1. Validation mechanism
I tested the Struts Validator Ted mentioned. Centralized xml config, 18n 
support, out of the box JavaScript for client side checks, ... great !

2. Transformation mechanism
I am looking for a way to benefit from java.util.Date automatic 
population in ActionForm like Strings or primitive types are.

2.1 The actual properties conversion takes place in 
org.apache.commons.beanutils.ConvertUtils this might be extended to 
support java.util.Date conversion.
2.2 Thanks to the Struts Validator it seems there is a generic way to 
know which date pattern is used for which field at submission time.
The ActionServlet or as proposed "(...). A transformation plugin to the 
Validator (...)" could exploit this to do any required request 
parameters pre-processing to let ConverUtils always receive dates of a 
similar pattern.

Do you think this could lead to a solution ?


Ted Husted wrote:

>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?
>>                    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?
>>>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
>>has been lost") without using Javascript...
>>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: <>

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

View raw message