[Struts] ActionForm not displayed  
Author Message
Wendy Smoak





PostPosted: 2005-3-1 2:05:00 Top

java-programmer, [Struts] ActionForm not displayed "Hamvil" <email***@***.com> wrote in message
news:email***@***.com...

> Basically i would like to fill a form with the data obtained from a
> database. Here follow a small part of the code:
>
> try {
> actionForm = registerManager.loadProfile(id);
> } catch (Exception e) {}
>
> basically actionForm is the one passed by the execute mathod.
>
> The method loadProfile returns an object RegisterBean (which extends
> ActionForm) that contain the user data loaded from the database.

I don't think you're supposed to construct your own form-- there's more to
it than the data. If you look at the API, you'll see some other attributes
that your own form is probably missing.
http://struts.apache.org/api/org/apache/struts/action/ActionForm.html

There is a way to ask the framework to make you a new form bean, but in this
case you don't really need that.

Instead of trying to replace the form bean with your own, try copying all of
the matching properties into it with:
BeanUtils.copyProperties( form, objectFromDatabase );

The Struts example webapp has an example of prepopulating a form. Using
forms as Data Transport Objects is generally frowned upon as it
unnecessarily couples your data access layer to Struts.

--
Wendy