You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Trieu, Danny" <DT...@ebuilt.com> on 2002/07/17 03:11:48 UTC

How do I navigate from one subApp to another in Struts1.1?

For example: I am in a page of a sub-application of a Struts application,
and I want to render a link that link you to another sub-application within
the application using the <html:link/> tag.
 
danny

Re: How do I navigate from one subApp to another in Struts1.1?

Posted by th...@part.net.
Craig R. McClanahan writes:
>  
> 
> On 26 Jul 2002, Troy Hart wrote: 
> 
>>
>> Craig, 
>>
>> What do you mean below??? I am trying to understand how sub-applications
>> work and I thought I had a handle on it, but I am now confused. Why/how
>> are you bypassing the controller servlet when using 
>>
>> <html:link forward="foo"/> 
>>
> 
> Let's assume that you have the "foo" forward defined as something like: 
> 
>   <!-- Home page of the "/bar" sub-application -->
>   <forward name="foo" path="/bar/index.jsp" contextRelative="true"/> 
> 
> and you use an <html:link> tag as above.  What does the generated HTML
> look like?  Assuming the context path is "/myapp" it looks like: 
> 
>   <a href="/myapp/bar/index.jsp"> 
> 
> which goes *directly* to the JSP page, not through the controller servlet.
> The Struts tags on this page will not understand that they are part of the
> "/bar" sub-application, because the controller never had a chance to set
> the right request attributes. 
> 
>> Can you tell me where my understanding of the this process breaks down?
>> I will spell out the major steps that are related to the sub-application
>> stuff as I see it: 
>>
>> 1) A request comes in to ActionServlet, which inspects the request path
>> to determine the sub-application to use (which may be the default app --
>> sub-app prefix = ""), and fetches the application configuration for that
>> sub-application.
> 
> This is the key step, isn't it?  What happens when a requst does *not*
> come in to the controller servlet?

Right. I had assumed the forward points to an action. I reckognize that the  
ActionServlet will not process the request otherwise. 

So, for situations that require sub-app A to render a page with a link to 
sub-app B, the practice of defining a context relative forward in sub-app 
A's config that maps to an *action* in sub-app B is solid. Would you agree? 
Or would there an advantage gained by using the SwitchAction? 

It seems to me that there is a bug in SwitchAction. By the time the jsp 
handles the request the application config request attribute has been 
switched and then switched back. Can you either confirm or deny this? 

Thanks for your comments, and thanks for the hard work that you and the 
other volunteers have put into this project. I think it ROCKS! 

Troy

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: How do I navigate from one subApp to another in Struts1.1?

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On 26 Jul 2002, Troy Hart wrote:

> Date: 26 Jul 2002 18:02:29 -0600
> From: Troy Hart <th...@part.net>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> To: Struts Users Mailing List <st...@jakarta.apache.org>
> Subject: Re: How do I navigate from one subApp to another in Struts1.1?
>
> Craig,
>
> What do you mean below??? I am trying to understand how sub-applications
> work and I thought I had a handle on it, but I am now confused. Why/how
> are you bypassing the controller servlet when using
>
> <html:link forward="foo"/>
>

Let's assume that you have the "foo" forward defined as something like:

  <!-- Home page of the "/bar" sub-application -->
  <forward name="foo" path="/bar/index.jsp" contextRelative="true"/>

and you use an <html:link> tag as above.  What does the generated HTML
look like?  Assuming the context path is "/myapp" it looks like:

  <a href="/myapp/bar/index.jsp">

which goes *directly* to the JSP page, not through the controller servlet.
The Struts tags on this page will not understand that they are part of the
"/bar" sub-application, because the controller never had a chance to set
the right request attributes.

> Can you tell me where my understanding of the this process breaks down?
> I will spell out the major steps that are related to the sub-application
> stuff as I see it:
>
> 1) A request comes in to ActionServlet, which inspects the request path
> to determine the sub-application to use (which may be the default app --
> sub-app prefix = ""), and fetches the application configuration for that
> sub-application.

This is the key step, isn't it?  What happens when a requst does *not*
come in to the controller servlet?

The answer is that the request attribute set by step 3) (I guess step 2 is
so magical nobody knows what it is :-) never gets set -- and Struts
consistently assumes that this means you are running in the default
sub-app.

> 3) The application configuration request attribute is updated to hold
> the current sub-app configuration.
> 4) The process() method of the sub-app specific request processor is
> invoked, which ultimately may end up forwarding to a jsp page that
> contains <html:link forward="foo"/>
> 5) html:link taglib code accesses the current sub-application
> configuration to lookup the global forward "foo" and renders the link
> appropriately. That is to say, if the current sub-app has defined a
> contextRelative forward named "foo" that references an action in the
> "goo" sub-app a link to some "goo" sub-app action will be rendered in
> the browser.
> 6) Now the page is rendered and the user clicks the link to the "goo"
> sub-app action.
>
> Is this request not bound for the action servlet? And/or will it not
> cause the action servlet to select the "goo" sub-application
> configuration?
>
> Also, I would like to be able to use the SwitchAction, but can not tet
> it to work. Does it really work for you in practice? From what I am able
> to gather no one has ever been successful at getting it to work and I
> wonder what you are doing differently.
>
> I've posted a few messages already on this topic, but I've never had a
> single response. If you could spare a few minutes to point me in the
> right direction I would greatly appreciate it. The company I work for is
> collaborating with 2 other companies to build a single struts
> application for the department of defense EMall. As you can well
> imagine, the sub-application features of struts are very desirable given
> our situation.
>
> Many thanks for any help I can get on this issue!
>
> Troy
>

Craig


> >
> > The tempting way to do this is to do something like
> >
> >   <html:link forward="foo"/>
> >
> > and mark the "foo" forward as being context relative.  However, this will
> > ONLY work if you are switching to the default sub-app, because you'd be
> > bypassing the controller servlet where sub-app selection is performed.
> >
> > The better way is to make your link go through an <action> that uses the
> > standard SwitchAction class.  This wants you to send along the application
> > prefix of the sub-app you want to switch to, as well as a resource in that
> > sub-app to forward to after the switch.
> >
> > > danny
> > >
> >
> > Craig
> >
>
>
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: How do I navigate from one subApp to another in Struts1.1?

Posted by Troy Hart <th...@part.net>.
Craig,

What do you mean below??? I am trying to understand how sub-applications
work and I thought I had a handle on it, but I am now confused. Why/how
are you bypassing the controller servlet when using

<html:link forward="foo"/>

Can you tell me where my understanding of the this process breaks down?
I will spell out the major steps that are related to the sub-application
stuff as I see it:

1) A request comes in to ActionServlet, which inspects the request path
to determine the sub-application to use (which may be the default app --
sub-app prefix = ""), and fetches the application configuration for that
sub-application. 
3) The application configuration request attribute is updated to hold
the current sub-app configuration.
4) The process() method of the sub-app specific request processor is
invoked, which ultimately may end up forwarding to a jsp page that
contains <html:link forward="foo"/>
5) html:link taglib code accesses the current sub-application
configuration to lookup the global forward "foo" and renders the link
appropriately. That is to say, if the current sub-app has defined a
contextRelative forward named "foo" that references an action in the
"goo" sub-app a link to some "goo" sub-app action will be rendered in
the browser.
6) Now the page is rendered and the user clicks the link to the "goo"
sub-app action.

Is this request not bound for the action servlet? And/or will it not
cause the action servlet to select the "goo" sub-application
configuration?

Also, I would like to be able to use the SwitchAction, but can not tet
it to work. Does it really work for you in practice? From what I am able
to gather no one has ever been successful at getting it to work and I
wonder what you are doing differently. 

I've posted a few messages already on this topic, but I've never had a
single response. If you could spare a few minutes to point me in the
right direction I would greatly appreciate it. The company I work for is
collaborating with 2 other companies to build a single struts
application for the department of defense EMall. As you can well
imagine, the sub-application features of struts are very desirable given
our situation.

Many thanks for any help I can get on this issue!

Troy

> 
> The tempting way to do this is to do something like
> 
>   <html:link forward="foo"/>
> 
> and mark the "foo" forward as being context relative.  However, this will
> ONLY work if you are switching to the default sub-app, because you'd be
> bypassing the controller servlet where sub-app selection is performed.
> 
> The better way is to make your link go through an <action> that uses the
> standard SwitchAction class.  This wants you to send along the application
> prefix of the sub-app you want to switch to, as well as a resource in that
> sub-app to forward to after the switch.
> 
> > danny
> >
> 
> Craig
> 



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: How do I navigate from one subApp to another in Struts1.1?

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Tue, 16 Jul 2002, Trieu, Danny wrote:

> Date: Tue, 16 Jul 2002 18:11:48 -0700
> From: "Trieu, Danny" <DT...@ebuilt.com>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> To: "'struts-user@jakarta.apache.org'" <st...@jakarta.apache.org>
> Cc: "'craigmcc@apache.org'" <cr...@apache.org>
> Subject: How do I navigate from one subApp to another in Struts1.1?
>
> For example: I am in a page of a sub-application of a Struts application,
> and I want to render a link that link you to another sub-application within
> the application using the <html:link/> tag.
>

The tempting way to do this is to do something like

  <html:link forward="foo"/>

and mark the "foo" forward as being context relative.  However, this will
ONLY work if you are switching to the default sub-app, because you'd be
bypassing the controller servlet where sub-app selection is performed.

The better way is to make your link go through an <action> that uses the
standard SwitchAction class.  This wants you to send along the application
prefix of the sub-app you want to switch to, as well as a resource in that
sub-app to forward to after the switch.

> danny
>

Craig



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>