File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes What Does This Action Mapping Do? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "What Does This Action Mapping Do?" Watch "What Does This Action Mapping Do?" New topic

What Does This Action Mapping Do?

JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
I have problem to understand the action mapping shown below. I am trying to figure out what the mapping does:

As I remember, when the forward property is specified, the servlet will not pass the request to an Action class but will make a call to RequestDispatcher.forward to the context-relative path of the resource. Therefore, the request will be passed to .article.Menu.
My questions are:
1. Apparently, name="success" is a condition. I am confused about to 'what' does this condition apply. E.g. the control will be passed to .article.Menu under the condition 'what' = "success"?
2. What is the meaning of name="menuForm"?
3. What is the meaning of parameter="application;HOURS"?
[ September 17, 2003: Message edited by: JiaPei Jen ]
Nagendra Prasad
Ranch Hand

Joined: Jul 11, 2002
Posts: 219
1. Apparently, name="success" is a condition. I am confused about to 'what' does this condition apply. E.g. the control will be passed to .article.Menu under the condition 'what' = "success"?

Yes... success is a condition. You would have to determine what is
your success condition. This is typically done in your action class.
So, in ur action class, (which is denoted by the type that is present in
your action), you would have some logic which will deetermine is the
condition is a success or failure.
When there is a condition of success, you want your code to go to a particular page or execute another piece of code. This is identified by
what is specified in the forward within the action.
IN your action class code, you would then include something like:
forward = mapping.findForward("success");
2. What is the meaning of name="menuForm"

This is the action that you try to execute. ie. either from code or in
the browser you would try to access the action in the form

QUOTE]3. What is the meaning of parameter="application;HOURS"?[
Actions can have parameters. This means that when menuForm is executed,
the parameters mentioned are available to you. You could use these to
evaluate conditions within the action class.

Best Regards,<br />Nagendra Prasad.
Junilu Lacar

Joined: Feb 26, 2001
Posts: 6529

Just some clarifications to the previous reply:
1. "success" is a logical name used in your application. As the Nagendra explained, you determine what criteria need to be met for this condition. In code, you would have something like:

In your code, you don't worry about the actual URI for success. All you have to worry about is getting the forward name right. Figuring out the actual URI is left to Struts. This allows you to change the URI without having to change code.
2. Actions and ActionForms are tightly coupled. That is, an Action will usually expect a specific type of ActionForm to be passed to its execute/perform method. The action-mapping attribute name="menuForm" tells Struts that this particular Action expects the ActionForm specified in the <form ...> section of struts-config.xml that has the name "menuForm".
3. The value for the parameter attribute specified goes to an ActionMapping. This value is accessed by invoking the ActionMapping.getParameter() method. It looks like your application expects a value in the given format and parses out two values: "application" and "HOURS". You'll have to go through your code to find how these two values are used--it's specific to your application.
[ September 18, 2003: Message edited by: Junilu Lacar ]

Junilu - [How to Ask Questions] [How to Answer Questions]
I agree. Here's the link:
subject: What Does This Action Mapping Do?
It's not a secret anymore!