File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Is the actionform the controller? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Is the actionform the controller?" Watch "Is the actionform the controller?" New topic
Author

Is the actionform the controller?

protik ahmed
Greenhorn

Joined: Mar 21, 2010
Posts: 15
Hi, I'm trying to get a better understanding of the Model 2 framework, looking at this diagram
http://www.mydeveloperconnection.com/html/strutstut_files/image005.gif

In my work, I have the client submitting some information via web browser. The struts-config.xml tells where to send that information. The data goes to the actionform, and then used by the action class. After hte actionclass is finished it forwards to a jsp page.

How does that fit into the diagram above? Can someone clarify what the diagram is showing in terms of how it fits into what I am doing? Maybe that image isn't a good example, but it is similar to a lot of other diagrams on the internet.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

The controller servlet is the controller, as its name implies. ActionForms are one way to get information to the view--it's sort of a bridge (or was originally intended to be) between the model and the view.
protik ahmed
Greenhorn

Joined: Mar 21, 2010
Posts: 15
So it's sort of like this?

http://bayimg.com/PaldjAaCl

Where would the JSP page go in this diagram, I am guessing it's between the controller and the client.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Yes, the JSP would be between the controller and the client, but the diagram isn't very clear in terms of what's happening when, and the action class doesn't return to the controller.
protik ahmed
Greenhorn

Joined: Mar 21, 2010
Posts: 15
Thanks for your reply.

So, by what you are saying, When sending something to the action class, say data in a form. The steps would be like this (in terms of the diagram)

A. Client will point to the controller
B. Controller would point to action form
C. Actionform would point to action class
D. Action class would point to JSP?
E. JSP would point to client

I thought the controller would be the struts-config file, when the action class uses something like forward.findmapping("PageX"), it will check the struts config file for the forward mapping, and forward to the relevant page.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

The struts-config file is just that, it's a file--it doesn't do anything. The controller servlet is the controller (hence the name). It *uses* the config file.
protik ahmed
Greenhorn

Joined: Mar 21, 2010
Posts: 15
ahh ok. So I've edited the image to look like this.
http://bayimg.com/malHGaACL

It is supposed to illustrate when a client does something like submit a form. The action class uses that information and forwards the user to another page, or updates the current JSP. I'm sure there is a hell of a lot more going on under the belt than that, but at it's most basic, is that image accurate?
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187

All of the Struts classes that have the term "Action" in front of them are part of the Controller. The Struts Controller is not implemented by a single class. It is implemented by a set of classes. At runtime, the Controller objects are all working together, e.g. ActionForm, ActionConfig, Action, ActionForward, ActionMapping, ActionServlet, etc.

Some of these Controller objects are part of the Struts code base. Some of the Controller objects are derived from data specified in the struts-config.xml files. And, finally, some of the Controller objects are written by application developers. This is how application developers build upon the framework to create their specific applications.

When the application is deployed, it reads the config file and creates the corresponding Controller objects in the JRE. Once this happens, the config file is never read again until the application is shut-down and restarted.

The ActionForm classes are written by the application developer and are for capturing HTML form data from the View and moving it into the Controller. Contrary to common misunderstandings, the ActionForm is not a Model object and should never touch Model code. Controller code extracts data from ActionForm, populates a Model data object and passes this to Model code.

So, the ActionForm is not the Controller, it is a small part of the Controller.

The application developer extends the Struts framework by writting custom ActionForm and Action classes. The application developer connects his custom classes with the core Struts code by creating the configuration XML file.
protik ahmed
Greenhorn

Joined: Mar 21, 2010
Posts: 15
Hi, it's just an image hosting website, I've uploaded the image to another well known host.

http://i871.photobucket.com/albums/ab272/s360fw/examplestruts.png

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is the actionform the controller?
 
Similar Threads
what is class diagram
Modelling increments in an incremetal development
Wiley Jakarta Pitfalls: Extend Struts ActionForms for array validation
upload a file from server using struts?-help urgent!
html:form tag inside logic:iterate