I used to use:
BeanUtils.copyProperties(theForm, cayenneObj);
I think the params are target object and then source object, so in the
example above swap them as required.
or you could use Tapestry ;)
----- Original message -----
From: "Mike Kienenberger" <mkienen..laska.net>
To: "Alex Gunawan Wibowo" <netzone_tec..ahoo.com>
Date: Wed, 24 Nov 2004 21:23:16 -0500
Subject: Re: Cayenne + Struts form..
Alex Gunawan Wibowo <netzone_tec..ahoo.com> wrote:
> I'm currently developing a web apps using Cayenne &
> Struts.
> The problem that I have right now is that say I want
> to add a new bean to the database.
> Do i have to get all fields from the form manually one
> by one, and set all property in the newly bean
> registered through DataContext manually one by one?
> Is there any faster way (e.g. using BeanUtils) ??
> I'm using DynaActionForm...
I generally do it all manually as I tend to need to either do additional
validation or slightly change what's put into the database.
However, if you have all of the same form and ObjEntity field names, you
could do it in a loop.
I think you can use DynaActionForm.getMap() to get all values for the
form
and iterate through them.
You could then use DataObject.writeProperty("key", value) to set them on
your data object.
Keep in mind that a DynaForm only stores Boolean and String values, so
your
DataObject could only have those two data types.
I've never used BeanUtils, and I don't know if it's flexible enough to
provide a generic interface to a DataObject.
I suspect worse case you could probably define a "set(key, value)"
method
for your DataObject (or whatever it expects) and make it work, though.
-Mike
This archive was generated by hypermail 2.0.0 : Wed Nov 24 2004 - 21:45:47 EST