I have been creating multiple methods and hoping I was doing the right
thing.  Looks like it is...

        public String getCreation() ;
        public Date getCreationAsDate() ;
        public int getCreationAsInt() ; // for epoc seconds I guess

The first method pulls from a String property and can be null, invalid or
valid.  The other two pull from a Date that is either null or validated
only.

When I validate, I only mess with the String, because it was suggested to me
a while ago that I have to allow for the String to be incorrect (like
setCreation("testing") instead of valid date).  If I immediately converted
and stored the value as Date, I'd never be able to repeat it to the browser
as typed.


Anthony

-----Original Message-----
From: Ted Husted [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, June 05, 2001 4:31 PM
To: [EMAIL PROTECTED]
Subject: Re: Proposed feature: Bean property transformations


I agree. 

The primary fields on an ActionForm must be Strings, ActionForms should
not be used to store persistent data, and the beans used to store
persistent data should use appropriate types. 

The peristent data beans should not have to worry about data
conversions, and so that task should be performed by a helper object.

But encapsulating the helper object within the ActionForm can be a valid
approach, since converting the String to a native type may be considered
part of the initial validation. Once this is done, the persistent data
bean can call a getPropertyInt or getPropertyDate method to retrieve the
native Property type (and then perhaps perform any business logic
validations).

It's just a matter of whether you prefer converting the data in the
Action or in the ActionForm validation method. A reuseable helper class
could be implemented in either case.

-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel 716 737-3463.
-- http://www.husted.com/about/struts/


Oleg V Alexeev wrote:
> What reason to store text values and data values in ActionForm? I
> think that more flexible approach is to use ActionForm with text only
> fields and data bean with native types, not String. In this case we
> can name all corresponded fields in data bean with same names as for
> ActionForm and use convert methods under it, for example, or use
> another convert methods.
>  We can convert text values to/from with one of the ways -
>  1. Perform conversion of all fields in some method in ActionForm, for
>     example import/export.
>  2. Make it in every setter/getter.
>  3. Write special helper class to perform conversion - in this case
>     more flexible approach can be used - one helper can handle
>     multiple sources and targets.
> 
> --
> Best regards,
>  Oleg                            mailto:[EMAIL PROTECTED]

Reply via email to