Re: Cayenne + Struts form..

From: Mike Kienenberger (mkienen..laska.net)
Date: Wed Nov 24 2004 - 21:23:16 EST

  • Next message: Steve Wells: "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:21:39 EST