You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Antonio Petrelli <br...@tariffenet.it> on 2006/02/28 12:20:29 UTC

[OT] The M in MVC (WAS: which method is better)

R.Vijayaraghavan ha scritto:
> 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.
>
>
>   

Ok I think we all should take a breath. Essentially there is not a 
"best" practice in how the controller should call the model.
There are various techniques (session façades, business delegates, 
IoC...) but anyway the controller is responsible to call the model.
All of these techniques, anyway, show their purpose to hide the fact 
that the model is used by a web-app.
 From my point of view, I think that IoC is the best way to call the 
model, because it reduces the levels of indirection in a cleaner way, 
but you have to use Spring or another IoC engine.
Anyway notice that the ActionForm is part of Struts and should not be 
referenced inside your model (though I once used it as a simple bean and 
took away its
property values by using BeanUtils, I don't know how correct it is...)

Just my 2 eurocents
Ciao
Antonio Petrelli

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [OT] The M in MVC (WAS: which method is better)

Posted by Michael Jouravlev <jm...@gmail.com>.
On 2/28/06, Antonio Petrelli <br...@tariffenet.it> wrote:
> R.Vijayaraghavan ha scritto:
> > 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.

Or, you can simply set your business object as a property of an
ActionForm, and use session-scoped ActionForm to retain value of
business object in between requests.

Michael.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org