You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Corneliu Rachieru <cr...@espial.com> on 2002/04/11 21:20:21 UTC
PropertyUtils.copyProperties question...
I have a bean called adminMap(a java.util.HashMap) defined that contains the
keys "id", "username", "password". I also have a DynaActionForm named form
defined in the struts-config.xml as
<form-bean name="adminForm"
dynamic="true"
type="org.apache.struts.action.DynaActionForm">
<form-property name="action" type="java.lang.String"/>
<form-property name="id"
type="java.lang.String"/>
<form-property name="username"
type="java.lang.String"/>
<form-property name="password"
type="java.lang.String"/>
</form-bean>
I've been trying to copy the contents of the my hashmap to the form using:
PropertyUtils.copyProperties(form, adminMap);
but that doesn't work (or at least it doesn't work in that form).
However, if i copy the properties like this it works fine.
((DynaActionForm) form).set("id", adminMap.get("id"));
((DynaActionForm) form).set("username", (String)
adminMap.get("username"));
((DynaActionForm) form).set("password", (String)
adminMap.get("password"));
I would really like to use PropertyUtils.copyProperties since that way i can
keep my application truly dynamic and i don't have to access any properties
in the actual code (except for struts-config but that's ok). Am I trying to
do something crazy here (it was my understanding that
PropertyUtils.copyProperties supports this, but i could be wrong) ? Also,
did anyone dynamically copy a hashmap to a DynaActionForm in any dynamic way
?
Thank you,
Corneliu
Re: PropertyUtils.copyProperties question...
Posted by Klaasjan Brand <br...@topicus.nl>.
Corneliu Rachieru wrote:
> I have a bean called adminMap(a java.util.HashMap) defined that contains the
> keys "id", "username", "password". I also have a DynaActionForm named form
> defined in the struts-config.xml as
>
> <form-bean name="adminForm"
> dynamic="true"
> type="org.apache.struts.action.DynaActionForm">
> <form-property name="action" type="java.lang.String"/>
> <form-property name="id"
> type="java.lang.String"/>
> <form-property name="username"
> type="java.lang.String"/>
> <form-property name="password"
> type="java.lang.String"/>
> </form-bean>
>
> I've been trying to copy the contents of the my hashmap to the form using:
>
> PropertyUtils.copyProperties(form, adminMap);
>
> but that doesn't work (or at least it doesn't work in that form).
> However, if i copy the properties like this it works fine.
>
> ((DynaActionForm) form).set("id", adminMap.get("id"));
> ((DynaActionForm) form).set("username", (String)
> adminMap.get("username"));
> ((DynaActionForm) form).set("password", (String)
> adminMap.get("password"));
>
> I would really like to use PropertyUtils.copyProperties since that way i can
> keep my application truly dynamic and i don't have to access any properties
> in the actual code (except for struts-config but that's ok). Am I trying to
> do something crazy here (it was my understanding that
> PropertyUtils.copyProperties supports this, but i could be wrong) ? Also,
> did anyone dynamically copy a hashmap to a DynaActionForm in any dynamic way
> ?
>
To copy from a map to a dynabean you need to use BeanUtils.populate.
I've used it and it works. Looking through the source code for BeanUtils
is a good idea because a lot of DynaBeans functionality is not
implemented yet...
greets,
Klaasjan
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>