You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Dan Allen <da...@mojavelinux.com> on 2003/04/18 07:53:48 UTC

validation parsing

I thought of a case which might be best handled by something
intermediatry to the struts validation engine.  Consider this case:

The form contains a field for a date and you either have the user
type in a data format manually or use your favorite date selector of
choice.  You decide on a required format and enforce it, such as

2003/04/18

When you get to the business logic, you hope that the validator does
it's job and that the date is in the correct format.  But actually,
you want more than that.  You want it to be a real java date object.
If the validator can enforce syntax, why can't it convert too?  If
the convert fails, then the form is not valid and you need to make
the user enter something else.

In short, how would I set it up so that at the top of my execute()
action the field containing this date already holds a nested Date
object rather than a String?  I could see this lending itself very
nicely to other objects as well, some custom, some standard.  So far
it does a nice job of converting from String to various other java
objects, but what about the case when parsing is required, such as
with dates and times?

Dan

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Daniel Allen, <da...@mojavelinux.com>
http://www.mojavelinux.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
[Frodo]: "I wish it need not have happened in my time." 
[Gandalf]: "So do I, and so do all who live to see such times. 
But that is not for them to decide. All we have to decide is 
what we do with the time that is given to us.'
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: validation parsing

Posted by Dan Allen <da...@mojavelinux.com>.
By the way, this would also allow for a change in data format
required in the form not to affect the struts action class (don't
have to recompile) since it could be specified (hopefully) in the
validation.xml document.

Dan

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Daniel Allen, <da...@mojavelinux.com>
http://www.mojavelinux.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
"If you are going to play the game of trial and error, 
don't be surprised when the results are revealing. -- me"
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: validation parsing

Posted by Dan Allen <da...@mojavelinux.com>.
Dan Allen (dan@mojavelinux.com) wrote:

> I thought of a case which might be best handled by something
> intermediatry to the struts validation engine.  Consider this case:
> 
> The form contains a field for a date and you either have the user
> type in a data format manually or use your favorite date selector of
> choice.  You decide on a required format and enforce it, such as
> 
> 2003/04/18
> 
> When you get to the business logic, you hope that the validator does
> it's job and that the date is in the correct format.  But actually,
> you want more than that.  You want it to be a real java date object.
> If the validator can enforce syntax, why can't it convert too?  If
> the convert fails, then the form is not valid and you need to make
> the user enter something else.
> 
> In short, how would I set it up so that at the top of my execute()
> action the field containing this date already holds a nested Date
> object rather than a String?  I could see this lending itself very
> nicely to other objects as well, some custom, some standard.  So far
> it does a nice job of converting from String to various other java
> objects, but what about the case when parsing is required, such as
> with dates and times?

I was in barnes and noble last night an caught the section in Struts
in Action on this very topic and just wanted to share.  Ted suggests
that you use a property with the text "Display" appended to the name
and then make cooresponding get/set methods in your data model.
These get/set methods will just parse the data to and from the
object stored in the persistence and not actually work with a
cooresponding object property with that name.  This way, the model
deals with the conversion both ways and the BeanUtils.copyProperties
will once again work.  Just wanted to mention that since this thread
didn't seem to go anywhere.

Dan

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Daniel Allen, <da...@mojavelinux.com>
http://www.mojavelinux.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Results! Why, man, I have gotten a ton of results! 
I know several thousand things that won't work! 
 --Thomas Edison
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org