[Strus] ActionForm not dispalyed

Discussion in 'Java' started by Hamvil, Feb 28, 2005.

  1. Hamvil

    Hamvil Guest

    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
    Hamvil, Feb 28, 2005
    #1
    1. Advertising

  2. Hamvil

    Wendy Smoak Guest

    Re: [Struts] ActionForm not displayed

    "Hamvil" <> wrote in message
    news:...

    > 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
    Wendy Smoak, Feb 28, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. PERCIVAL BRAGG
    Replies:
    0
    Views:
    535
    PERCIVAL BRAGG
    Oct 15, 2003
  2. milkyway
    Replies:
    5
    Views:
    722
    Robert kebernet Cooper
    Dec 25, 2004
  3. milkyway
    Replies:
    0
    Views:
    323
    milkyway
    Dec 25, 2004
  4. Dennis Dahn

    [strus] tiles, menu static?

    Dennis Dahn, Aug 28, 2005, in forum: Java
    Replies:
    1
    Views:
    438
    Andrew Thompson
    Aug 28, 2005
  5. Stefan Dammeier

    [strus] LOCALE

    Stefan Dammeier, Aug 30, 2005, in forum: Java
    Replies:
    0
    Views:
    401
    Stefan Dammeier
    Aug 30, 2005
Loading...

Share This Page