[Strus] ActionForm not dispalyed

H

Hamvil

Hi,

I have a problem with with the struts framework. I've already looked
in the news for an answer but i've found nothing.

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.

After the output is forwarded to edit.jsp, but nothing is displayed in
the form.

If for example i replace the previous code with:

((RegisterBean)actionForm).setName("Something");

everything works fine and the name is correctly displayed in the form.

It seems that by assigning to the actionForm another object the struts
environment lost the binding with the form.

Can anyone help me???

Thanks
Roberto
 
W

Wendy Smoak

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top