I do something like:
public class ProductAction extends Action
{
execute()
{
String name = (String)PropertyUtils.getSimpleProperty(form,
"name");
String age = (String)PropertyUtils.getSimpleProperty(form,
"age");
ProductModel model = new ProductModel();
model.setName(name);
model.setAge(age);
model.saveToPersistentStore();
}
}
I was wondering if the ActionForm can be used as a DTO. Something like this,
public class ProductAction extends Action
{
execute()
{
ProductModel model = new ProductModel();
model.setForm(form); // action form reference which the
execute method
gets
model.saveToPersistentStore();
}
}
I do not know which method will be better. I don't even know if there is any
other technique we should follow as Oshima pointed it.
regards,
vijay.
> -----Original Message-----
> From: Oshima Tlholoe [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, February 28, 2006 2:53 PM
> To: Struts Users Mailing List
> Subject: Re: which method is better
>
>
> With my rudimentary knowledge,I dont think its advisable for your Action
> classes to talk directly to your business layer/model classes,
> Why don't you
> have a business delegate/session facade or Service Locator sitting between
> your Action Classes and the model classes, this insulates your action
> classes from your business layer and it even makes testing
> simpler. You not
> going to have test cases that span multiple layers.
> Let your Actions pull out data from the ActionForm, wrap it and pass it to
> the Service Locator, then the Service Locator then handles the
> rest, calling
> all the related model classes.
>
>
>
> On 2/28/06, R.Vijayaraghavan <[EMAIL PROTECTED]> wrote:
> >
> > Hello,
> >
> > I usually have set and get methods for all properties in my Model class.
> > After submitting a form, I pull out all the property values
> (form fields)
> > in
> > the Action class from the ActionForm object, set the values of all
> > properties in the model from the action class and then call a particular
> > method in the model class for final submission to the database.
> >
> > I wanted to know thether the above mentioned method is better or is it
> > better to pass the form reference itself to the Model class which then
> > sets
> > the values.
> >
> > In situation 2, I do not have to take care of the various String
> > references
> > that I create. I simply will pass the ActionForm object to the Model
> > class.
> >
> > regards,
> > vijay.
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
>
> --
> Regards
> Name : Oshima Tlholoe
> Cell No: +2773 342 4393
> Tel No : +2712 841 4355(w)
> E-mail : [EMAIL PROTECTED]
> simplicity is the ultimate sophistication
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]