This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
The above is basically correct except for one thing: The Action does not belong to the Model space, but rather is also part of the controller along with ActionServlet. As such, it should not contain business logic, but rather instantiate and call methods on other classes that do contain business logic.
While Struts provides a framework for you to write MVC applications, it provides no classes at all that are part of the model space. The expectation is that you will write these classes yourself, or tie into another framework such as EJBs or Spring to help you write the model.
Due to conflict on Action's role I have posted this question. There are two school of thoughts one which consider Action as model (like me and Rama Krishna Ghanta) and others have thought like Merrill Higginson. These two thoughts are confusing me.
As per my understanding, ActionServlet calls execute of Action to process the request or to perform the business logic against that request. So as per role Action is model. Now its upto us how we implement our logic in Action, whether we write whole business logic in Action or delegate it to other layers[DAO, Business Logic layer or EJB].
One thing that I read in struts best practices is
Struts is a presentation layer framework and we should not use its Action for Application logic as the Action is model for presentation layer
So if we forget about our application and just think of Struts framework then Action seems model of the framework (where we integrate our application model layer or business logic layer) or the struts framework do not provide modle layer
Hi Amir, Model layer doesn't belong to struts framework..that's the layer where we write the business logic. The Model starts where the struts ends. ActionServlet and Actions belong to Controler part and ActionForms & jsps belong to View. And Model consists of business logic which we write.
This should clear your confusion... happy coding...
Joined: Feb 15, 2005
One of the criteria for writing a good model component is that it should be agnostic as to which type of presentation layer will be used. For example, it shouldn't know or care whether it is being presented in HTML, or in a client-side GUI, or whatever. Does the excecute method of an Action class pass this test? No, it does not. It requires an HttpServletRequest and HttpServletResponse as parameters.
As to whether the Struts authors consider the Action class to be a controller component or a model component, one only has to look as far as the User Guide. You will find all the information on creating Action classes under the main heading "Building Controller Componenets".
Note: This is not the first time this topic has been discussed in this forum. See this thread for an in-depth discussion of this topic. [ December 26, 2006: Message edited by: Merrill Higginson ]