You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Jan Mikkelsen <jm...@adslhome.dk> on 2003/06/02 00:02:31 UTC

Current URL

Hi All,

In a menu component I would like to get the url that is currently
selected in order to be able to highlight the relevant menu item. How do
I do that?

Regards, Jan

Re: Current URL

Posted by Mindbridge <mi...@yahoo.com>.
Hi,

    I think you are looking for in the case you describe is the name of the
page that is currently being rendered. You can get this in the following
way:
        getPage().getPageName()


    In case you still want the URL (be careful though -- many different URLs
may theoretically render the same page), you can do:
        IRequestCycle cycle = getPage().getRequestCycle(); // this is
usually unnecessary, since cycle is usually passed as an argument to the
method
        IRequestContext context = cycle.getRequestContext();
        String uri = context.getRequestURI();
        String url = context.getRequest().getRequestURL().toString();


    Finally, another approach you may also want to consider is passing the
location information to the component via a parameter/binding -- this is
useful when you have one page object render multiple visual "pages" from the
view point of the user. (In general I would stay away from the request
URL -- there are many other alternatives)


Best regards,
-mb

----- Original Message ----- 
From: "Jan Mikkelsen" <jm...@adslhome.dk>
To: "Tapestry users" <ta...@jakarta.apache.org>
Sent: Monday, June 02, 2003 1:02 AM
Subject: Current URL


> Hi All,
>
> In a menu component I would like to get the url that is currently
> selected in order to be able to highlight the relevant menu item. How do
> I do that?
>
> Regards, Jan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org