You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Stjepan Brbot <st...@ht.hr> on 2004/04/14 20:16:13 UTC

Converting DTO into formBean and vice versa

I have DTO (transfering the data from my EJB) with the following fields:

    id (java.lang.Integer),
    name (java.lang.String),
    birth (java.sql.Date)

also I have a ActionForm bean with the same fields but of String types:

    id (java.lang.String),
    name (java.lang.String),
    birth (java.lang.String)

my web application implements I18N and deals with German and English locales so when user must insert a date in HTML form german user inserts the date into String field of ActionForm bean in "dd.mm.yyyy" format (according to DateFormat (MEDIUM) of "de" locale) and english user inserts the date in "mm/dd/yyyy" format (according to DateFormat (MEDIUM) of "en" locale).

To transfer all data fields from FORM into DTO where I do not have date field I can use:

    BeanUtils.copyProperties(myDto,myActionForm)

Now I'd like to have the similar functionlity where I will be able to have java.sql.Date field in my DTO object providing BeanUtils with particular DateFormat of current Locale. Is there anything like that? E.g. LocaleBeanUtils(myDto,myActionForm,dateFormat)?

Stjepan Brbot


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


Re: Converting DTO into formBean and vice versa

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
String -> java.sql.Date is possible with BeanUtils. Write a plugin to
register a Converter with ConvertUtils at app startup.

Actually I believe there are skeleton classes for LocaleBeanUtils to do
what you want, but they haven't been programmed yet. Perhaps you should
check on jakarta about their status. Somebody might have done it.

I had this issue a year ago or so and due to time constraints I dropped
the localized dates and I force my users to enter date format YYYY-MM-DD.

Adam

On 04/14/2004 08:16 PM Stjepan Brbot wrote:
> I have DTO (transfering the data from my EJB) with the following
> fields:
> 
> id (java.lang.Integer), name (java.lang.String), birth
> (java.sql.Date)
> 
> also I have a ActionForm bean with the same fields but of String
> types:
> 
> id (java.lang.String), name (java.lang.String), birth
> (java.lang.String)
> 
> my web application implements I18N and deals with German and English
> locales so when user must insert a date in HTML form german user
> inserts the date into String field of ActionForm bean in "dd.mm.yyyy"
> format (according to DateFormat (MEDIUM) of "de" locale) and english
> user inserts the date in "mm/dd/yyyy" format (according to DateFormat
> (MEDIUM) of "en" locale).
> 
> To transfer all data fields from FORM into DTO where I do not have
> date field I can use:
> 
> BeanUtils.copyProperties(myDto,myActionForm)
> 
> Now I'd like to have the similar functionlity where I will be able to
> have java.sql.Date field in my DTO object providing BeanUtils with
> particular DateFormat of current Locale. Is there anything like that?
> E.g. LocaleBeanUtils(myDto,myActionForm,dateFormat)?
> 
> Stjepan Brbot
> 
> 
> ---------------------------------------------------------------------
>  To unsubscribe, e-mail: user-unsubscribe@struts.apache.org For
> additional commands, e-mail: user-help@struts.apache.org
> 
> 


-- 
struts 1.2 + tomcat 5.0.19 + java 1.4.2
Linux 2.4.20 Debian



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