• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

global-forwards

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I searched a bit on <global-forwards> and my understanding is that in the Action class, the ActionMapping object will try to look for the local forward defined in the <action-mappings> tag, if it is not found in that, it will then look for the <global-forwards> declaration.

I am having a problem in that the Action class is not able to find the <global-forwards> declarations.


In the list of forwards that is printed, I am not able to see the global forward value that was declared in the <global-forwards> section.

Can anybody help?
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When in doubt, read the Javadocs. Here is the entry for findForward:

Find and return the ForwardConfig instance defining how forwarding to the specified logical name should be handled. This is performed by checking local and then global configurations for the specified forwarding configuration. If no forwarding configuration can be found, return null.


Here's The entry for findForwards:

Return the logical names of all locally defined forwards for this mapping. If there are no such forwards, a zero-length array is returned.


Note that findForwards only returns locally defined, not global forwards. If you want an array of the global forwards, use the findForwardConfigs method.
[ June 28, 2007: Message edited by: Merrill Higginson ]
 
Bhaskar Reddy
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Merrill for your pointer...

I did see the JavaDocs. The entry for findForward says that findForward() returns local or global forward with the specified name -


public ActionForward findForward(java.lang.String forwardName)

Find and return the ForwardConfig instance defining how forwarding to the specified logical name should be handled. This is performed by checking local and then global configurations for the specified forwarding configuration. If no forwarding configuration can be found, return null.

Parameters:
forwardName - Logical name of the forwarding instance to be returned
Returns:
The local or global forward with the specified name.


That was the reason, I had the opinion I initially stated. If there was a error in my understanding, I would like to stand corrected.

If I want to use actionMapping.findForwardConfig("notLoggedIn") [instead of actionMapping.findForward("notLoggedIn")] how would I go about doing it? The former returns ForwardConfig object.
I would like the request to be sent to the path specified by the name "notLoggedIn" in <global-forwards> section of the struts-config.xml

Appreciate your help!
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bhaskar Reddy:

In the list of forwards that is printed, I am not able to see the global forward value that was declared in the <global-forwards> section.


The reason the global forward did not appear in the list is that you used findForwards to create the list, and as the Javadocs clearly state, this method does not retrieve global forwards.

However, the statement:

should have returned the correct global forward because findForward does search for global forwards. If the statement doesn't return the correct forward, there's something wrong somewhere. I guess I'm not understanding why you need to print a list of the forwards. Isn't it enough just to return the right one?
 
Bhaskar Reddy
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I actually wanted to forward it to the global-forward mentioned by the name="notLoggedIn". But since it was not working, I tried to see a list of forwards that are available at run-time and hence I used findForwards.

The real requirement is to forward all the requests to "home.do" if they dont have the session variable "userId".

And the way I am doing it is
1. to extend Action class in MyBaseAction and in the execute method, check for the session variable "userId", if not found, return actionMapping.findForward("notLoggedIn"); else (ie, if "userId" is found) return null.
2. All other Action classes will extend MyBaseAction and call super.execute() as their first statement (so that appropriate action is taken if the session variable 'userId' is not present).
3. The code sections are as under -


Do let me know if I am missing something...
 
Bhaskar Reddy
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It now works! The issue was more on the "return" flow that <<MyOtherActionClasses>> were not returning what <<MyBaseAction>> was returning (in case of "userId" not being available in session).

I wanted to have all this logic (check for "userId"; if present -> do this; else do that in one place in <<MyBaseAction>> rather than scattered in all <<MyOtherActionClasses>>. However, this doesnt seem to be possible.

Anyone has any thoughts on how to go about doing this? Appreciate your quick response!
 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Isn't it possible to extend the Action or DispatchAction and all other action classes extend this new extendedDispatchAction class?

Wonder what difference does it make really!


wanted to have all this logic (check for "userId"; if present -> do this; else do that in one place in <<MyBaseAction>> rather than scattered in all <<MyOtherActionClasses>>. However, this doesnt seem to be possible.

 
This tiny ad is suggesting that maybe she should go play in traffic.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic