Struts ActionForm/EJB best practice?

G

grz01

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?
 
J

Jean-Baptiste Nizet

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.
 
G

grz01

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,
 

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

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top