wood burning stoves 2.0*
The moose likes Struts and the fly likes Struts Question about global forwards and action mapping Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts Question about global forwards and action mapping" Watch "Struts Question about global forwards and action mapping" New topic
Author

Struts Question about global forwards and action mapping

Kim Kantola
Ranch Hand

Joined: May 17, 2001
Posts: 274
Hello All,
Could you please help me clear up a bit of Struts navigation confusion?
1. Am I making the correct assumption that when using an Action Mapping action, or a form action, that the struts forward action (or class that extends it)is always called first, and then the jsp page is rendered?
2. In reference to question #1 above, in my struts-config file, I see that the "Global forwards" only show a forward name and a path, is there no struts forward Action class called before rendering the jsp page mentioned in the path?

Thank you!
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30764
    
156

Kim,
1. Yes, this is a correct assumption.
2. Usually these gloabl forwards are used for error pages. If you want to call an action first, have the forward as the path name for the action. (As if you were linking to the action through a web page.)


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Kim Kantola
Ranch Hand

Joined: May 17, 2001
Posts: 274
Thank you so much for your reply, that is a big help to me.
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

To add to that, the order of operations is:

Get the ActionMapping.
Get the ActionForm from specified scope or create a new one if it does not exist.
Call the reset method on the form.
Call the set methods on the form from the values submitted.
Call the validate method of the form if validate is set to true in the ActionMapping (or default).
- If validation fails, send to the input forward.
Call the execute method on the Action being used.
Use the forward returned from the action to find where to go next.
- If the forward is not found in ActionMapping, look in global forwards (a forward in an ActionMapping can override a global forward for that mapping).
- Pass the request along to the forward's path.


A good workman is known by his tools.
Kim Kantola
Ranch Hand

Joined: May 17, 2001
Posts: 274
Thank you so much everyone. While I have your attention, mind if I ask one more from a high level perspective? When it comes to struts ActionForms, are the members of the form class not neccessarily meant to match an actual form on the page, i.e., if you have a logon form that asks for a name and password, is it proper for the form to contain data members other than

I would like to determine in my Action class if the user is of a certain catagory, and then set it in the form, even though this data doesn't actually show up on the page, so I would have in my form class


Is this proper struts form?
Thanks again very much for helping me out.
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

ActionForms should be passive and not know much. Aside from the validate method, they should be 99% just a holder for user-entered data.

I would think that the only context where a managerCode might be important within Struts is in the Action, unless there is a field in your jsp where the user enters the value. MAYBE you would use it in the ActionForm's validate method but even then it should only have scope of the validate method itself.

What is the code used for?
Kim Kantola
Ranch Hand

Joined: May 17, 2001
Posts: 274
Hi,
My Form accepts a user name and password, depending on the type of employee that the user is, differant types of information are shown on the main page of the web application. So what I am trying to do, is process the Login Form, take the user, find out if they are a manager or not, and save the manager code to the form, then, when I start to draw the page from within the JSP, I look at the manager code value from the form to decide on page content. I am guessing from what you said, that this is not the way to go, but I can't figure out where else I would perform this kind of thing, thanks so much for your input if you can think of a better place for me to lookup and save the value of this managerCode,
Kim
Kim Kantola
Ranch Hand

Joined: May 17, 2001
Posts: 274
Hi,
I left something out of my last entry. I get the username and password from my UserForm, but then in my corresponding Action class, this is where i get the name from the form, find the manager code, and then call the set method on the form class to set the manager code in the form. So, the work of determining the manager code is done in the action class,
Kim
 
jQuery in Action, 2nd edition
 
subject: Struts Question about global forwards and action mapping