• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Actionservlet is model or controller

 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all



My doubt is whether MyAction class is Controller or Model

One of our Colleagues says it is Controller
another stands for Model

I waiting for ur suggestions
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it's neither model nor controller.
It connects model with the controller. You consider Action classes as a ModelHelper !
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The function of a controller object is to serve as a mediator between the view and the model. A Struts Action class does exactly that. It gets information from the view, sends it on to model object, and returns results to the view.

In my mind, a Struts action belongs firmly in the controller space.
[ January 12, 2006: Message edited by: Merrill Higginson ]
 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Action class forwards request to ActionServlet(controller) and ActionServlet decides where to forward based on struts-config mapping.

ActionServlet receives and processes all requests that change the state of a user's interaction with the application. The servlet delegates the handling of a request to a RequestProcessor object. ActionServlet represents the "controller" component of an MVC architecture.

The RequestProcessor selects and invokes an Action class or delegates the response to another resource.

The Action classes can manipulate the state of the application's interaction with the user, typically by creating or modifying JavaBeans.

Instead of producing the next page of the user interface directly, Action classes generally return an ActionForward to indicate which resource should handle the response. If the Action does not return null, the RequestProcessor forwards or redirects to the specified resource (by utilizing RequestDispatcher.forward or Response.sendRedirect) so as to produce the next page of the user interface.

Action classes are not controller.

Originally posted by Merrill Higginson:
The function of a controller object is to serve as a mediator between the view and the model. A Struts Action class does exactly that. It gets information from the view, sends it on to model object, and returns results to the view.

In my mind, a Struts action belongs firmly in the controller space.

[ January 12, 2006: Message edited by: Merrill Higginson ]

 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While I agree with Vicky that the Struts ActionServlet is the main controller component, I continue to assert that the Action class is also part of the controller space. While it is the ActionServlet and RequestProcessor that actually communicate with the model, the Action class tells them both what to do ... which page to display next, and what data will go on that page.

To me, the real test of which space a component belongs in is "what does it need to know about?". View objects should know only about other view objects and controller objects, as they should never communicate directly to the model. Model objects only need to know about other model objects. They should be "pluggable" to use any view or controller. Conroller objects, on the other hand, need to know about both view objects and model objects in order to mediate between them.

What does the Action class need to know about?

It needs to know about the view. Although it doesn't need to know the name of a JSP, it does need to the name of an ActionForward that will eventually resolve to a JSP. It needs to know that we're using HTTP as the view protocol, because it receives it's input from an HTTPServletRequest and sends its output to an HTTPServletRespone. It needs to know about the javaBeans that are part of the view space in order to pass data to the view.

It needs to know about the model. It has to know which model objects to call in order to get the needed information. It has to know what format that information will be in and may have to modify it to accomodate the view.

Given this test, the Action class is clearly a controller object -- certainly not the only controller object, nor even the main one, but a controller object nonetheless.

The authors of the Struts documentation appear to agree with me on this. They list Action Mappings and Action classes as conroller components. Here's the link:

http://struts.apache.org/struts-doc-1.2.x/userGuide/introduction.html#controllerConcepts
[ January 13, 2006: Message edited by: Merrill Higginson ]
 
vidya sagar
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for ur replies
 
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Merrill is quite correct. The Action class is part of the Controller, and not in any way part of the model. If there were any question as to how the authors of Struts grouped the various components, the Struts User Guide states it quite plainly. Aside from explicitly listing Action as a controller component, it states the following:

The goal of an Action class is to process a request, via its execute method, and return an ActionForward object that identifies where control should be forwarded (e.g. a JSP, Tile definition, Velocity template, or another Action) to provide the appropriate response.



That's a pretty good description of what a controller component does.
[ January 14, 2006: Message edited by: Jason Menard ]
 
You don't know me, but I've been looking all over the world for. Thanks to the help from this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic