You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mete Kural <me...@yahoo.com> on 2002/07/17 20:27:43 UTC

Action classes: Controller or Model.. or are the lines blurry?

Hello,

I came to the point while developing my Struts web-app
that I am confused if I'm doing things the right way.
My Action classes:

1) Retrieve the values submitted through html forms
via ActionForm beans.
2) Make calls to a DAO (data access object) in order
to make changes to the database and make sure that the
DAO returned a success code.
3) Update the session beans accordingly.
4) Forward control to the view.

This is what the Struts user guide says in section
1.4:

"In some smaller scale applications, on the other
hand, the available actions might be embedded within
the Action classes that are part of the Controller
role. This is appropriate when the logic is very
simple, or where reuse of the business logic in other
environments is not contemplated. The Struts framework
supports any of these approaches, but strongly
recommends separating the business logic ("how it's
done") from the role that Action classes play ("what
to do")."

So here we are told that the Action classes are part
of the Controller. But this is what section 1.6 says:

"In Struts, the primary component of the Controller is
a servlet of class ActionServlet. This servlet is
configured by defining a set of ActionMappings. An
ActionMapping defines a path that is matched against
the request URI of the incoming request, and usually
specifies the fully qualified class name of an Action
class. All Actions are subclassed from
org.apache.struts.action.Action. Actions encapsulate
the business logic, interpret the outcome, and
ultimately dispatch control to the appropriate View
component to create the response."

So the Action classes "encapsulate the business
logic". What does this exactly mean? Am I simply
encapsulating the business logic in my Action classes
or did I get into the model as well?

Thanks,
Mete




__________________________________________________
Do You Yahoo!?
Yahoo! Autos - Get free new car price quotes
http://autos.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Action classes: Controller or Model.. or are the lines blurry?

Posted by Mete Kural <me...@yahoo.com>.
Hello Craig,

--- "Craig R. McClanahan" <cr...@apache.org> wrote:
> For the "small applications" case where you really
> do embed the business
> logic in your Actions, you can make a case that the
> Action is part of the
> model.  The preferred case for any reasonable sized
> app, however, is that
> you encapsulate your business logic in external
> classes (either EJBs or
> regular JavaBeans).  In that scenario you can think
> of the Action itself
> as a "script" that just calls the right business
> logic methods in the
> right order.  In that case, it's acting like part of
> the controller.

Thanks for your help. My goal is to encapsulate
business logic in external classes. Do you think
statements such as these below should be encapsulated
in business logic or are these roles of the
controller?

These statements are directly coded in my Action
class. They retrieve the values from an ActionForm
"one by one" and update the session bean with them:

EditProfileForm editProfileForm =
(EditProfileForm)form;
User editUser = editProfileForm.getUser();
User user =
(User)session.getAttribute(Constants.USER_KEY);
user.setFirstName(editUser.getFirstName());
user.setLastName(editUser.getLastName());
user.setEmail(editUser.getEmail());
user.setAddress(editUser.getAddress());

> 
> Craig

Thanks,
Mete







> On Wed, 17 Jul 2002, Mete Kural wrote:
> 
> > Date: Wed, 17 Jul 2002 11:27:43 -0700 (PDT)
> > From: Mete Kural <me...@yahoo.com>
> > Reply-To: Struts Users Mailing List
> <st...@jakarta.apache.org>
> > To: struts-user@jakarta.apache.org
> > Subject: Action classes: Controller or Model.. or
> are the lines blurry?
> >
> > Hello,
> >
> > I came to the point while developing my Struts
> web-app
> > that I am confused if I'm doing things the right
> way.
> > My Action classes:
> >
> > 1) Retrieve the values submitted through html
> forms
> > via ActionForm beans.
> > 2) Make calls to a DAO (data access object) in
> order
> > to make changes to the database and make sure that
> the
> > DAO returned a success code.
> > 3) Update the session beans accordingly.
> > 4) Forward control to the view.
> >
> > This is what the Struts user guide says in section
> > 1.4:
> >
> > "In some smaller scale applications, on the other
> > hand, the available actions might be embedded
> within
> > the Action classes that are part of the Controller
> > role. This is appropriate when the logic is very
> > simple, or where reuse of the business logic in
> other
> > environments is not contemplated. The Struts
> framework
> > supports any of these approaches, but strongly
> > recommends separating the business logic ("how
> it's
> > done") from the role that Action classes play
> ("what
> > to do")."
> >
> > So here we are told that the Action classes are
> part
> > of the Controller. But this is what section 1.6
> says:
> >
> > "In Struts, the primary component of the
> Controller is
> > a servlet of class ActionServlet. This servlet is
> > configured by defining a set of ActionMappings. An
> > ActionMapping defines a path that is matched
> against
> > the request URI of the incoming request, and
> usually
> > specifies the fully qualified class name of an
> Action
> > class. All Actions are subclassed from
> > org.apache.struts.action.Action. Actions
> encapsulate
> > the business logic, interpret the outcome, and
> > ultimately dispatch control to the appropriate
> View
> > component to create the response."
> >
> > So the Action classes "encapsulate the business
> > logic". What does this exactly mean? Am I simply
> > encapsulating the business logic in my Action
> classes
> > or did I get into the model as well?
> >
> > Thanks,
> > Mete
> >
> >
> >
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Yahoo! Autos - Get free new car price quotes
> > http://autos.yahoo.com
> >
> > --
> > To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> >
> >
> 
> 
> --
> To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 


__________________________________________________
Do You Yahoo!?
Yahoo! Autos - Get free new car price quotes
http://autos.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Action classes: Controller or Model.. or are the lines blurry?

Posted by "Craig R. McClanahan" <cr...@apache.org>.
For the "small applications" case where you really do embed the business
logic in your Actions, you can make a case that the Action is part of the
model.  The preferred case for any reasonable sized app, however, is that
you encapsulate your business logic in external classes (either EJBs or
regular JavaBeans).  In that scenario you can think of the Action itself
as a "script" that just calls the right business logic methods in the
right order.  In that case, it's acting like part of the controller.

Craig


On Wed, 17 Jul 2002, Mete Kural wrote:

> Date: Wed, 17 Jul 2002 11:27:43 -0700 (PDT)
> From: Mete Kural <me...@yahoo.com>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> To: struts-user@jakarta.apache.org
> Subject: Action classes: Controller or Model.. or are the lines blurry?
>
> Hello,
>
> I came to the point while developing my Struts web-app
> that I am confused if I'm doing things the right way.
> My Action classes:
>
> 1) Retrieve the values submitted through html forms
> via ActionForm beans.
> 2) Make calls to a DAO (data access object) in order
> to make changes to the database and make sure that the
> DAO returned a success code.
> 3) Update the session beans accordingly.
> 4) Forward control to the view.
>
> This is what the Struts user guide says in section
> 1.4:
>
> "In some smaller scale applications, on the other
> hand, the available actions might be embedded within
> the Action classes that are part of the Controller
> role. This is appropriate when the logic is very
> simple, or where reuse of the business logic in other
> environments is not contemplated. The Struts framework
> supports any of these approaches, but strongly
> recommends separating the business logic ("how it's
> done") from the role that Action classes play ("what
> to do")."
>
> So here we are told that the Action classes are part
> of the Controller. But this is what section 1.6 says:
>
> "In Struts, the primary component of the Controller is
> a servlet of class ActionServlet. This servlet is
> configured by defining a set of ActionMappings. An
> ActionMapping defines a path that is matched against
> the request URI of the incoming request, and usually
> specifies the fully qualified class name of an Action
> class. All Actions are subclassed from
> org.apache.struts.action.Action. Actions encapsulate
> the business logic, interpret the outcome, and
> ultimately dispatch control to the appropriate View
> component to create the response."
>
> So the Action classes "encapsulate the business
> logic". What does this exactly mean? Am I simply
> encapsulating the business logic in my Action classes
> or did I get into the model as well?
>
> Thanks,
> Mete
>
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Autos - Get free new car price quotes
> http://autos.yahoo.com
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>