You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Peter Werno <pe...@werno.com> on 2004/10/05 16:32:37 UTC

global forwards in module config files

Hello,

I am just in the course of moving from 1.0.x to 1.2 and the new version
should make heavy use of the modules that came with 1.1.
Now here is my problem:

I want to store a global forward in any module's config file named
"moduleHome" where "module" would be replaced with the actual module name.

In the "main" app, I want to have an action "loadModule.do" that should be
told where to forward to via a parameter.

While this works well, as long as the global forwards are all in the
"main" config file, it fails as soon as I put them in the individual
module-config-files.
Is this a "known feature", or am I just doing something wrong?

This is how it works:

--------- struts-config.xml ----------

<struts-config>
    ...

    <global-forwards>
        <forward name="home" path="/index.jsp" redirect="false"/>
        <forward name="loginform" path="/login.jsp" redirect="false"/>
        <forward name="error500" path="/error/err500.jsp" redirect="false"/>
        <forward name="trylogin" path="/loginAction.do" redirect="false"/>
        <forward name="indexHome" contextRelative="true"
path="/index/index.do" redirect="true"/>
        .... more ....
    </global-forwards>
    ...
</struts-config>

--------- end ---------

this is how it does NOT work:

--------- struts-config.xml ----------

<struts-config>
    ...

    <global-forwards>
        <forward name="home" path="/index.jsp" redirect="false"/>
        <forward name="loginform" path="/login.jsp" redirect="false"/>
        <forward name="error500" path="/error/err500.jsp" redirect="false"/>
        <forward name="trylogin" path="/loginAction.do" redirect="false"/>
    </global-forwards>
    ...
</struts-config>

--------- index-config.xml ----------

<struts-config>
    ...
    <global-forwards>
        <forward name="indexHome" contextRelative="true" path="index.do"
redirect="true"/>
    </global-forwards>
    ...
</struts-config>

--------- end ---------

many thanks,

Peter

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: global forwards in module config files

Posted by Peter Werno <pe...@werno.com>.
Hi Jeff,

thanks for the hint. Using the "include file" variant is probably a
work-around for my problem, but it doesn't really allow for what I was
planning.
My idea was to have a global forwards section in each module that would be
global for the application. Each module could that way define, how it can
be "contacted" from other modules.
Apparently, "global" seems to only mean "global for the module" and not
"global for the application".

Writing it in a separate file and include this in all config files will
work, but it's just as good as writing the global forwards form moduleX in
all other module's config files.

I will probably try to write config files for my modules, defining those
globals in each of the module-config-files, but instead of including them
as modules in the web.xml, I just include them as a comma-separated list
in the config parameter....

If you know of any other way to solve this issue, please let me know.

Regards,

Peter

> Have you read
> http://struts.apache.org/userGuide/configuration.html#module_config-switching?
>   It explains how to use contextRelative forwards in Module A to forward
> to pages in Module B.
>
> If that's not what you need, you could define all of your
> application-global forwards in an XML external entity file and reference
> that in the global-forwards section of each of your module configuration
> files.
>
> 1) Create a file called global-forwards.xml that looks like this:
>
> <forward name="indexHome" contextRelative="true" path="/index/index.do"
> redirect="true"/>
> <forward name="modAHome" contextRelative="true" path="/modA/index.do"
> redirect="true"/>
>
> ... and so forth
>
> 2) Declare this file as an external entity in each of your module
> configuration files:
>
> <!DOCTYPE struts-config PUBLIC "public-id" "systemid
> [ ENTITY globalForwards SYSTEM "../path/to/global-forwards.xml" ]>
>
> 3) Create a global-forwards section in each module that looks like so:
> <global-forwards>
>   <!-- Module-global forwards -->
>   <forward name="page1" path="page1.do"/>
>   <forward name="page2" path="page2.do"/>
>   <!-- Pull in the contents of the globalForwards entity -->
>   &globalForwards;
> </globalForwards>
>
> Peter Werno wrote:
>> Hello Jeff,
>>
>> thanks for the hint. I had tested multiple variations of it, including
>> /index/index.do, but to no avail. I have checked in the Action Class
>> that
>> tries to get it. It does
>>
>> -----
>>
>> ActionForward myForward = mapping.findForward("indexHome");
>> if(myForward == null)
>>     System.out.println("Forward is null!!!");
>>
>> -----
>> and it returns null allways. I even tried different names
>> ("index/indexHome", "/index/indexHome", etc.)
>>
>> This Action Class is actually belonging to the "DEFAULT" part of the
>> webapp. Is it possible that "global" forwards are only global for the
>> module that they are defined in?
>>
>> In that case, modules will probably be a no-go for me :/
>>
>> Regards,
>>
>> Peter
>>
>>
>>
>>>Peter Werno wrote:
>>>
>>>>This is how it works:
>>>>
>>>>--------- struts-config.xml ----------
>>>>
>>>><struts-config>
>>>>    ...
>>>>
>>>>    <global-forwards>
>>>>        <forward name="home" path="/index.jsp" redirect="false"/>
>>>>        <forward name="loginform" path="/login.jsp" redirect="false"/>
>>>>        <forward name="error500" path="/error/err500.jsp"
>>>>redirect="false"/>
>>>>        <forward name="trylogin" path="/loginAction.do"
>>>>redirect="false"/>
>>>>        <forward name="indexHome" contextRelative="true"
>>>>path="/index/index.do" redirect="true"/>
>>>>        .... more ....
>>>>    </global-forwards>
>>>>    ...
>>>></struts-config>
>>>>
>>>>--------- end ---------
>>>>
>>>>this is how it does NOT work:
>>>>
>>>>--------- index-config.xml ----------
>>>>
>>>><struts-config>
>>>>    ...
>>>>    <global-forwards>
>>>>        <forward name="indexHome" contextRelative="true"
>>>> path="index.do"
>>>>redirect="true"/>
>>>>    </global-forwards>
>>>>    ...
>>>></struts-config>
>>>>
>>>>--------- end ---------
>>>>
>>>>many thanks,
>>>>
>>>>Peter
>>>
>>>I think you're confused on the meaning of contextRelative.
>>>contextRelative means to interpret the path relative to the web
>>>application root, not the module root.  So in your second example, the
>>>forward named 'indexHome' will attempt to find /index.do, not
>>>/index/index.do as the first example.
>>>
>>>-- Jeff
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>For additional commands, e-mail: user-help@struts.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: global forwards in module config files

Posted by Jeff Beal <jb...@webmedx.com>.
Have you read 
http://struts.apache.org/userGuide/configuration.html#module_config-switching? 
  It explains how to use contextRelative forwards in Module A to forward 
to pages in Module B.

If that's not what you need, you could define all of your 
application-global forwards in an XML external entity file and reference 
that in the global-forwards section of each of your module configuration 
files.

1) Create a file called global-forwards.xml that looks like this:

<forward name="indexHome" contextRelative="true" path="/index/index.do" 
redirect="true"/>
<forward name="modAHome" contextRelative="true" path="/modA/index.do" 
redirect="true"/>

... and so forth

2) Declare this file as an external entity in each of your module 
configuration files:

<!DOCTYPE struts-config PUBLIC "public-id" "systemid
[ <!ENTITY globalForwards SYSTEM "../path/to/global-forwards.xml"> ]>

3) Create a global-forwards section in each module that looks like so:
<global-forwards>
  <!-- Module-global forwards -->
  <forward name="page1" path="page1.do"/>
  <forward name="page2" path="page2.do"/>
  <!-- Pull in the contents of the globalForwards entity -->
  &globalForwards;
</globalForwards>

Peter Werno wrote:
> Hello Jeff,
> 
> thanks for the hint. I had tested multiple variations of it, including
> /index/index.do, but to no avail. I have checked in the Action Class that
> tries to get it. It does
> 
> -----
> 
> ActionForward myForward = mapping.findForward("indexHome");
> if(myForward == null)
>     System.out.println("Forward is null!!!");
> 
> -----
> and it returns null allways. I even tried different names
> ("index/indexHome", "/index/indexHome", etc.)
> 
> This Action Class is actually belonging to the "DEFAULT" part of the
> webapp. Is it possible that "global" forwards are only global for the
> module that they are defined in?
> 
> In that case, modules will probably be a no-go for me :/
> 
> Regards,
> 
> Peter
> 
> 
> 
>>Peter Werno wrote:
>>
>>>This is how it works:
>>>
>>>--------- struts-config.xml ----------
>>>
>>><struts-config>
>>>    ...
>>>
>>>    <global-forwards>
>>>        <forward name="home" path="/index.jsp" redirect="false"/>
>>>        <forward name="loginform" path="/login.jsp" redirect="false"/>
>>>        <forward name="error500" path="/error/err500.jsp"
>>>redirect="false"/>
>>>        <forward name="trylogin" path="/loginAction.do"
>>>redirect="false"/>
>>>        <forward name="indexHome" contextRelative="true"
>>>path="/index/index.do" redirect="true"/>
>>>        .... more ....
>>>    </global-forwards>
>>>    ...
>>></struts-config>
>>>
>>>--------- end ---------
>>>
>>>this is how it does NOT work:
>>>
>>>--------- index-config.xml ----------
>>>
>>><struts-config>
>>>    ...
>>>    <global-forwards>
>>>        <forward name="indexHome" contextRelative="true" path="index.do"
>>>redirect="true"/>
>>>    </global-forwards>
>>>    ...
>>></struts-config>
>>>
>>>--------- end ---------
>>>
>>>many thanks,
>>>
>>>Peter
>>
>>I think you're confused on the meaning of contextRelative.
>>contextRelative means to interpret the path relative to the web
>>application root, not the module root.  So in your second example, the
>>forward named 'indexHome' will attempt to find /index.do, not
>>/index/index.do as the first example.
>>
>>-- Jeff
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>For additional commands, e-mail: user-help@struts.apache.org



Re: global forwards in module config files

Posted by Peter Werno <pe...@werno.com>.
Hello Jeff,

thanks for the hint. I had tested multiple variations of it, including
/index/index.do, but to no avail. I have checked in the Action Class that
tries to get it. It does

-----

ActionForward myForward = mapping.findForward("indexHome");
if(myForward == null)
    System.out.println("Forward is null!!!");

-----
and it returns null allways. I even tried different names
("index/indexHome", "/index/indexHome", etc.)

This Action Class is actually belonging to the "DEFAULT" part of the
webapp. Is it possible that "global" forwards are only global for the
module that they are defined in?

In that case, modules will probably be a no-go for me :/

Regards,

Peter


> Peter Werno wrote:
>> This is how it works:
>>
>> --------- struts-config.xml ----------
>>
>> <struts-config>
>>     ...
>>
>>     <global-forwards>
>>         <forward name="home" path="/index.jsp" redirect="false"/>
>>         <forward name="loginform" path="/login.jsp" redirect="false"/>
>>         <forward name="error500" path="/error/err500.jsp"
>> redirect="false"/>
>>         <forward name="trylogin" path="/loginAction.do"
>> redirect="false"/>
>>         <forward name="indexHome" contextRelative="true"
>> path="/index/index.do" redirect="true"/>
>>         .... more ....
>>     </global-forwards>
>>     ...
>> </struts-config>
>>
>> --------- end ---------
>>
>> this is how it does NOT work:
>>
>> --------- index-config.xml ----------
>>
>> <struts-config>
>>     ...
>>     <global-forwards>
>>         <forward name="indexHome" contextRelative="true" path="index.do"
>> redirect="true"/>
>>     </global-forwards>
>>     ...
>> </struts-config>
>>
>> --------- end ---------
>>
>> many thanks,
>>
>> Peter
>
> I think you're confused on the meaning of contextRelative.
> contextRelative means to interpret the path relative to the web
> application root, not the module root.  So in your second example, the
> forward named 'indexHome' will attempt to find /index.do, not
> /index/index.do as the first example.
>
> -- Jeff
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: global forwards in module config files

Posted by Jeff Beal <jb...@webmedx.com>.
Peter Werno wrote:
> This is how it works:
> 
> --------- struts-config.xml ----------
> 
> <struts-config>
>     ...
> 
>     <global-forwards>
>         <forward name="home" path="/index.jsp" redirect="false"/>
>         <forward name="loginform" path="/login.jsp" redirect="false"/>
>         <forward name="error500" path="/error/err500.jsp" redirect="false"/>
>         <forward name="trylogin" path="/loginAction.do" redirect="false"/>
>         <forward name="indexHome" contextRelative="true"
> path="/index/index.do" redirect="true"/>
>         .... more ....
>     </global-forwards>
>     ...
> </struts-config>
> 
> --------- end ---------
> 
> this is how it does NOT work:
> 
> --------- index-config.xml ----------
> 
> <struts-config>
>     ...
>     <global-forwards>
>         <forward name="indexHome" contextRelative="true" path="index.do"
> redirect="true"/>
>     </global-forwards>
>     ...
> </struts-config>
> 
> --------- end ---------
> 
> many thanks,
> 
> Peter

I think you're confused on the meaning of contextRelative. 
contextRelative means to interpret the path relative to the web 
application root, not the module root.  So in your second example, the 
forward named 'indexHome' will attempt to find /index.do, not 
/index/index.do as the first example.

-- Jeff


RE: global forwards in module config files

Posted by "David G. Friedman" <hu...@ix.netcom.com>.
Peter,

In your web.xml, does your Struts ActionServlet have init params just like
this: (per your mesage below)

<init-param>
	<param-name>config</param-name>
	<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
	<param-name>config/index</param-name>
	<param-value>/WEB-INF/index-config.xml</param-value>
</init-param>

If not, then how are you specifing your struts config .xml files to the
ActionServlet?
See manual page:
http://struts.apache.org/userGuide/configuration.html#module_config-inform_c
ontroller

Regards,
David

-----Original Message-----
From: Peter Werno [mailto:peter@werno.com]
Sent: Tuesday, October 05, 2004 10:33 AM
To: user@struts.apache.org
Subject: global forwards in module config files


Hello,

I am just in the course of moving from 1.0.x to 1.2 and the new version
should make heavy use of the modules that came with 1.1.
Now here is my problem:

I want to store a global forward in any module's config file named
"moduleHome" where "module" would be replaced with the actual module name.

In the "main" app, I want to have an action "loadModule.do" that should be
told where to forward to via a parameter.

While this works well, as long as the global forwards are all in the
"main" config file, it fails as soon as I put them in the individual
module-config-files.
Is this a "known feature", or am I just doing something wrong?

This is how it works:

--------- struts-config.xml ----------

<struts-config>
    ...

    <global-forwards>
        <forward name="home" path="/index.jsp" redirect="false"/>
        <forward name="loginform" path="/login.jsp" redirect="false"/>
        <forward name="error500" path="/error/err500.jsp" redirect="false"/>
        <forward name="trylogin" path="/loginAction.do" redirect="false"/>
        <forward name="indexHome" contextRelative="true"
path="/index/index.do" redirect="true"/>
        .... more ....
    </global-forwards>
    ...
</struts-config>

--------- end ---------

this is how it does NOT work:

--------- struts-config.xml ----------

<struts-config>
    ...

    <global-forwards>
        <forward name="home" path="/index.jsp" redirect="false"/>
        <forward name="loginform" path="/login.jsp" redirect="false"/>
        <forward name="error500" path="/error/err500.jsp" redirect="false"/>
        <forward name="trylogin" path="/loginAction.do" redirect="false"/>
    </global-forwards>
    ...
</struts-config>

--------- index-config.xml ----------

<struts-config>
    ...
    <global-forwards>
        <forward name="indexHome" contextRelative="true" path="index.do"
redirect="true"/>
    </global-forwards>
    ...
</struts-config>

--------- end ---------

many thanks,

Peter

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org