You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Mark <ma...@xeric.net> on 2011/04/25 01:28:18 UTC

Link to root

What is the best way to get the url of the root of a web application? In
other words, If I'm on a page like:
http://server:8080/appname/mypage?showAll=true

I want to get:
http://server:8080/appname

I tried using:
pageRenderLinkSource.createPageRenderLink("Index").toAbsoluteURI();

But that seems to retain the Request Parameters.  I could use a regex to
strop them off, but I'm guessing that I'm missing a better way to do it.

Mark

Re: Link to root

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Sun, 24 Apr 2011 23:05:02 -0300, Mark <ma...@xeric.net> wrote:

> Thanks Brian and Taha.   I know I can build what I need by combining  
> both of your suggestions.  I wanted to make sure there wasn't a simple  
> way to get
> what I wanted without needing to build it manually, but it doesn't sound
> like there is another way to get this directly from Tapestry.

@Inject
private PageRenderLinkSource pageRenderLinkSource;

Link link =  
pageRenderLinkSource.createPageRenderLinkWithContext(Index.class);
String url = link.toAbsoluteURI();

By the way, you can get the HttpServletRequest @Inject'ing it directly,  
not needing to use RequestGlobals.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Link to root

Posted by Mark <ma...@xeric.net>.
Thanks Brian and Taha.   I know I can build what I need by combining both of
your suggestions.  I wanted to make sure there wasn't a simple way to get
what I wanted without needing to build it manually, but it doesn't sound
like there is another way to get this directly from Tapestry.

Thanks for your help.

Mark

On Sun, Apr 24, 2011 at 8:15 PM, Taha Hafeez <ta...@gmail.com>wrote:

> Try
>
> @Inject
> private RequestGlobals requestGlobals;
>
> requestGlobals.getHttpServletRequest().getContextPath()
>
> regards
> Taha
>
>
> On Mon, Apr 25, 2011 at 6:37 AM, Bryan Lewis <jb...@gmail.com>
> wrote:
>
> > One way to do it:
> >
> >
> >    @Inject private Request request;
> >
> >    ...
> >        int port = request.getServerPort();
> >        String serverName = request.getServerName();
> >
> >
> >
> > On Sun, Apr 24, 2011 at 7:28 PM, Mark <ma...@xeric.net> wrote:
> >
> > > What is the best way to get the url of the root of a web application?
> In
> > > other words, If I'm on a page like:
> > > http://server:8080/appname/mypage?showAll=true
> > >
> > > I want to get:
> > > http://server:8080/appname
> > >
> > > I tried using:
> > > pageRenderLinkSource.createPageRenderLink("Index").toAbsoluteURI();
> > >
> > > But that seems to retain the Request Parameters.  I could use a regex
> to
> > > strop them off, but I'm guessing that I'm missing a better way to do
> it.
> > >
> > > Mark
> > >
> >
>

Re: Link to root

Posted by Taha Hafeez <ta...@gmail.com>.
Try

@Inject
private RequestGlobals requestGlobals;

requestGlobals.getHttpServletRequest().getContextPath()

regards
Taha


On Mon, Apr 25, 2011 at 6:37 AM, Bryan Lewis <jb...@gmail.com> wrote:

> One way to do it:
>
>
>    @Inject private Request request;
>
>    ...
>        int port = request.getServerPort();
>        String serverName = request.getServerName();
>
>
>
> On Sun, Apr 24, 2011 at 7:28 PM, Mark <ma...@xeric.net> wrote:
>
> > What is the best way to get the url of the root of a web application? In
> > other words, If I'm on a page like:
> > http://server:8080/appname/mypage?showAll=true
> >
> > I want to get:
> > http://server:8080/appname
> >
> > I tried using:
> > pageRenderLinkSource.createPageRenderLink("Index").toAbsoluteURI();
> >
> > But that seems to retain the Request Parameters.  I could use a regex to
> > strop them off, but I'm guessing that I'm missing a better way to do it.
> >
> > Mark
> >
>

Re: Link to root

Posted by Bryan Lewis <jb...@gmail.com>.
One way to do it:


    @Inject private Request request;

    ...
        int port = request.getServerPort();
        String serverName = request.getServerName();



On Sun, Apr 24, 2011 at 7:28 PM, Mark <ma...@xeric.net> wrote:

> What is the best way to get the url of the root of a web application? In
> other words, If I'm on a page like:
> http://server:8080/appname/mypage?showAll=true
>
> I want to get:
> http://server:8080/appname
>
> I tried using:
> pageRenderLinkSource.createPageRenderLink("Index").toAbsoluteURI();
>
> But that seems to retain the Request Parameters.  I could use a regex to
> strop them off, but I'm guessing that I'm missing a better way to do it.
>
> Mark
>