Struts ActionForm/EJB best practice?

Discussion in 'Java' started by grz01, Sep 11, 2008.

  1. grz01

    grz01 Guest

    Have a Struts/EJB question...

    If I have a web-form backed by an ActionForm in Struts, where the user
    types in a record that maps directly to an EJB3 entity class and a
    corresponding db-table, is it advisable (or even possible) to somehow
    use the same class for the ActionForm and the EJB?

    Im thinking the 2 beans, they have basically the same setter/getter
    methods,
    but the form-bean extends ActionForm, while the Entity class
    implements serializable...

    Is it possible to use one and the same class for both purposes... or
    maybe one extends the other...

    Or should they just be two different classes, and have to copy data
    back and forth between them?

    What is "best practice" here?
     
    grz01, Sep 11, 2008
    #1
    1. Advertising

  2. On 11 sep, 18:22, grz01 <> wrote:
    > Have a Struts/EJB question...
    >
    > If I have a web-form backed by an ActionForm in Struts, where the user
    > types in a record that maps directly to an EJB3 entity class and a
    > corresponding db-table, is it advisable (or even possible) to somehow
    > use the same class for the ActionForm and the EJB?
    >
    > Im thinking the 2 beans, they have basically the same setter/getter
    > methods,
    > but the form-bean extends ActionForm, while the Entity class
    > implements serializable...
    >
    > Is it possible to use one and the same class for both purposes... or
    > maybe one extends the other...
    >
    > Or should they just be two different classes, and have to copy data
    > back and forth between them?
    >
    > What is "best practice" here?


    Your form bean must extend ActionForm, and you don't want your
    persistent entities to depend on Struts, so your form bean can't be a
    subclass of your entity. Moreover, if you want your form to be
    validateable, it must be able to contain invalid dates, numbers, etc.,
    so all its properties should be Strings. The best practice is to have
    separate classes and copy data back and forth.

    JB.
     
    Jean-Baptiste Nizet, Sep 12, 2008
    #2
    1. Advertising

  3. grz01

    grz01 Guest

    On Sep 12, 1:58 pm, Jean-Baptiste Nizet <> wrote:
    > On 11 sep, 18:22, grz01 <> wrote:
    >
    >
    >
    > > Have a Struts/EJB question...

    >
    > > If I have a web-form backed by an ActionForm in Struts, where the user
    > > types in a record that maps directly to an EJB3 entity class and a
    > > corresponding db-table, is it advisable (or even possible) to somehow
    > > use the same class for the ActionForm and the EJB?

    >
    > > Im thinking the 2 beans, they have basically the same setter/getter
    > > methods,
    > > but the form-bean extends ActionForm, while the Entity class
    > > implements serializable...

    >
    > > Is it possible to use one and the same class for both purposes... or
    > > maybe one extends the other...

    >
    > > Or should they just be two different classes, and have to copy data
    > > back and forth between them?

    >
    > > What is "best practice" here?

    >
    > Your form bean must extend ActionForm, and you don't want your
    > persistent entities to depend on Struts, so your form bean can't be a
    > subclass of your entity. Moreover, if you want your form to be
    > validateable, it must be able to contain invalid dates, numbers, etc.,
    > so all its properties should be Strings. The best practice is to have
    > separate classes and copy data back and forth.
    >
    > JB.



    Thanks for input, JB.
    Yes, that makes sense now :)

    Regards,
     
    grz01, Sep 12, 2008
    #3
    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. tom
    Replies:
    2
    Views:
    961
    code learner
    Dec 24, 2010
  2. Rode
    Replies:
    0
    Views:
    860
  3. PERCIVAL BRAGG
    Replies:
    0
    Views:
    551
    PERCIVAL BRAGG
    Oct 15, 2003
  4. Pratap Das
    Replies:
    2
    Views:
    2,042
    Pratap Das
    Apr 5, 2004
  5. Raymond Schanks
    Replies:
    0
    Views:
    663
    Raymond Schanks
    Aug 3, 2010
Loading...

Share This Page