You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by teknokrat <te...@yahoo.com> on 2003/03/18 13:39:20 UTC
confused about an action forms fields
Do all the fields of an actionform have to be strings? I am confused as
to when a form field should become an entity in my business logic. For
example, I have quite complex business objects composed of ArrayLists,
Dates and other classes. How are these to be set? Do I need to capture
everything as a primitive type and then have my action build the complex
business entity? if I am updating an already existing entitiy do I need
to change every field in it manually?
thanks
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: confused about an action forms fields
Posted by Nicolas De Loof <ni...@cgey.com>.
You can register a new converter for your data types
http://jakarta.apache.org/commons/beanutils/api/org/apache/commons/bea
nutils/ConvertUtils.html#register(org.apache.commons.beanutils.Convert
er, java.lang.Class)
You will need to build a RoleConverter, that has access to your Role
objetcs, and does convertion based on string roleName.
Nico.
>
> Am i right in that BeanUtil can only copy basic data types and not
> complex data types that i have created myself? Presumably if I have
a
> form that allows changing a user's role ( which is of type Role ) i
need
> to compare the string roleName returned by the form with a cache of
> possible role objects and if one exists with that name assign it to
the
> user manually.
>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: confused about an action forms fields
Posted by teknokrat <te...@yahoo.com>.
Nicolas De Loof wrote:
> As user can edit them, you should set all actionform fields as string.
> You can use Collection, arrays and references to obects with String
> fields.
>
> This way you can build a "formbean" model that has the same look as
> your business object model (or data transfert objects). You can the
> use BeanUtil.copyProperties() to populate DTO datas to a formbean and
> afert user edited it (and validation occured)transfert formbean datas
> to DTO back.
>
> FormBean are this way a "String-copy" of your business, that user can
> edit. BeanUtil will convert data types (you can register converters if
> needed)
>
> Nico.
Am i right in that BeanUtil can only copy basic data types and not
complex data types that i have created myself? Presumably if I have a
form that allows changing a user's role ( which is of type Role ) i need
to compare the string roleName returned by the form with a cache of
possible role objects and if one exists with that name assign it to the
user manually.
>
>>Do all the fields of an actionform have to be strings? I am confused
>
> as
>
>>to when a form field should become an entity in my business logic.
>
> For
>
>>example, I have quite complex business objects composed of
>
> ArrayLists,
>
>>Dates and other classes. How are these to be set? Do I need to
>
> capture
>
>>everything as a primitive type and then have my action build the
>
> complex
>
>>business entity? if I am updating an already existing entitiy do I
>
> need
>
>>to change every field in it manually?
>>
>>thanks
>>
>>
>>
>>--------------------------------------------------------------------
>
> -
>
>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: confused about an action forms fields
Posted by Nicolas De Loof <ni...@cgey.com>.
As user can edit them, you should set all actionform fields as string.
You can use Collection, arrays and references to obects with String
fields.
This way you can build a "formbean" model that has the same look as
your business object model (or data transfert objects). You can the
use BeanUtil.copyProperties() to populate DTO datas to a formbean and
afert user edited it (and validation occured)transfert formbean datas
to DTO back.
FormBean are this way a "String-copy" of your business, that user can
edit. BeanUtil will convert data types (you can register converters if
needed)
Nico.
> Do all the fields of an actionform have to be strings? I am confused
as
> to when a form field should become an entity in my business logic.
For
> example, I have quite complex business objects composed of
ArrayLists,
> Dates and other classes. How are these to be set? Do I need to
capture
> everything as a primitive type and then have my action build the
complex
> business entity? if I am updating an already existing entitiy do I
need
> to change every field in it manually?
>
> thanks
>
>
>
> --------------------------------------------------------------------
-
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org