Hello group,

This has probably been done many times before, but since I couldn't find a
diagram of how Struts implements the MVC pattern, I made one.  

Please take a look at it and see if I got anything wrong, then perhaps
someone could put it in a prominent place in the Users Guide.  I think it
would help give everyone a better handle on the big Struts picture.  

I put ActionForm in the View box to be consistent with the User Guide
comments.  This was the subject of some discussion last week, so let me know
if anyone objects.  Personally, I think it should go in the Model box since
it holds state, doesn't control flow, and doesn't determine how things
appear to the user, but I'll go along with the consensus.

Thanks,
Dan


Here are some notes to go with the diagram.

Step 1:
A request comes into the Server.

Step 2:
The ActionServlet looks in its <action-mappings> for the Action and then in
the <form-beans> for the Form Bean (if any) for the given request url.  It
retrieves the Form Bean from a context container or creates one, resets its
fields, and calls its validate() method to validate the new Request data.

Step 3: 
The ActionServlet passes the Form Bean to the Action's perform() method.

Step 4:
The Action invokes methods on business object(s).  The business object(s)
does some work.

Step 5:
The business object returns a result to the Action.

Step 6:
The Action updates the Form Bean if necessary with results from the Business
Object(s).  This is where the Action can set properties of the Form Bean
using Value Objects (a.k.a. Data Transfer Objects) .

Step 7:
The Action returns a success, failure, or other ActionForward object to the
ActionServlet.

Step 8:
The ActionServlet looks in its ActionMappings and finds the appropriate page
for the given Action and ActionForward, then forwards to that page.

Step 9:
The page contains forms(s) containing tag(s) that get information from the
ActionForm(s) and the ResourceBundles.

Step 10:
The response is returned to the client.


Notes about stuff that might not be obvious:
Form Beans: 
1) It's necessary to create a Form Bean rather than have the page refer
directly to the business objects because getting info from the Form Bean is
foolproof, but getting info from the Business Objects could run into
problems.  A page could not handle these gracefully since it is sent to the
client as it is processed, so there's no way to redirect if there's a
problem in the middle of the page.  
2) Using hidden request parameters instead of a Form Bean to maintain state
is not as secure and requires more overhead.


 <<Struts_MVC.gif>> 


Attachment: Struts_MVC.gif
Description: GIF image

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to