handling parameters passed through the url path

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

handling parameters passed through the url path

John
Suppose I want to pass a parameter like this:

http://somedomain.com/JohnSmith

instead of http://somedomain.com?username=JohnSmith

so the parameter looks like a subdirectory.

Can a tapestry page plus some kind of service hande this?
Reply | Threaded
Open this post in threaded view
|

Re: handling parameters passed through the url path

Mats Andersson-2
Easy, I would go as far as to say that this is the preferred way in
Tapestry. See:
http://tapestry.apache.org/page-navigation.html
for examples of onActivate() and onPassivare().

/Mats
 
____________________________________________Mats AnderssonRonsoft AB -
Fridhemsvägen 8 - 372 25 RonnebyTel. 073-368 79
82http://www.ronsoft.se____________________________________________

----- Original Message -----
From: "Tapestry users"
To:
Cc:
Sent:Sun, 27 Jan 2013 11:39:36 -0000
Subject:handling parameters passed through the url path

 Suppose I want to pass a parameter like this:

 http://somedomain.com/JohnSmith

 instead of http://somedomain.com?username=JohnSmith

 so the parameter looks like a subdirectory.

 Can a tapestry page plus some kind of service hande this?


Reply | Threaded
Open this post in threaded view
|

Re: handling parameters passed through the url path

Thiago H de Paula Figueiredo
In reply to this post by John
On Sun, 27 Jan 2013 09:39:36 -0200, John <[hidden email]> wrote:

> Suppose I want to pass a parameter like this:
> http://somedomain.com/JohnSmith
> instead of http://somedomain.com?username=JohnSmith
> so the parameter looks like a subdirectory.
> Can a tapestry page plus some kind of service hande this?

That's the page activation context:  
http://tapestry.apache.org/page-navigation.html, specially section "Page  
Activation".

Basically, on a page class:

void onActivate(String username) {
        // username will get the first parameter in the URL (slash separated)
}

--
Thiago H. de Paula Figueiredo

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: handling parameters passed through the url path

John
is there a root page then, do I need to program this in my Index page, or am I better something like this

somedomain.com/p/JackSmith

Where p is a page and JackSmith is the username?

John
  ----- Original Message -----
  From: Thiago H de Paula Figueiredo
  To: Tapestry users
  Sent: Sunday, January 27, 2013 11:45 AM
  Subject: Re: handling parameters passed through the url path


  On Sun, 27 Jan 2013 09:39:36 -0200, John <[hidden email]> wrote:

  > Suppose I want to pass a parameter like this:
  > http://somedomain.com/JohnSmith
  > instead of http://somedomain.com?username=JohnSmith
  > so the parameter looks like a subdirectory.
  > Can a tapestry page plus some kind of service hande this?

  That's the page activation context:  
  http://tapestry.apache.org/page-navigation.html, specially section "Page  
  Activation".

  Basically, on a page class:

  void onActivate(String username) {
  // username will get the first parameter in the URL (slash separated)
  }

  --
  Thiago H. de Paula Figueiredo

  ---------------------------------------------------------------------
  To unsubscribe, e-mail: [hidden email]
  For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: handling parameters passed through the url path

Thiago H de Paula Figueiredo
On Sun, 27 Jan 2013 10:13:33 -0200, John <[hidden email]> wrote:

> is there a root page then, do I need to program this in my Index page,  
> or am I better something like this

The Index page is the root page.

> somedomain.com/p/JackSmith
> Where p is a page and JackSmith is the username?

If you'll need more stuff like that in your app, having a single page  
handling all them will be a mess.

--
Thiago H. de Paula Figueiredo

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: handling parameters passed through the url path

John
So, I can pick up the /UserName in my index page and forwards to the required page, although of course that will limit me to only handling 1 parameter linked to 1 page.

I am also finding that resources such as this in my layout.tml
            <img src="layout/images/page_bg.png" border="0" width="960" height="799" alt="" style="position:absolute;left:0px;top:149px;"/>
cannot be located when I request pages with params in the url. Is there some way to reference the root context in my layout paths?

John

  ----- Original Message -----
  From: Thiago H de Paula Figueiredo
  To: Tapestry users
  Sent: Sunday, January 27, 2013 12:35 PM
  Subject: Re: handling parameters passed through the url path


  On Sun, 27 Jan 2013 10:13:33 -0200, John <[hidden email]> wrote:

  > is there a root page then, do I need to program this in my Index page,  
  > or am I better something like this

  The Index page is the root page.

  > somedomain.com/p/JackSmith
  > Where p is a page and JackSmith is the username?

  If you'll need more stuff like that in your app, having a single page  
  handling all them will be a mess.

  --
  Thiago H. de Paula Figueiredo

  ---------------------------------------------------------------------
  To unsubscribe, e-mail: [hidden email]
  For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: handling parameters passed through the url path

Thiago H de Paula Figueiredo
On Sun, 27 Jan 2013 10:47:08 -0200, John <[hidden email]> wrote:

> So, I can pick up the /UserName in my index page and forwards to the  
> required page, although of course that will limit me to only handling 1  
> parameter linked to 1 page.

Actually, you can have as much parameters as you want:  
onActivate(EventContext context). This will handle any number of  
parameters, all them accessed through the context parameter.

> I am also finding that resources such as this in my layout.tml
>             <img src="layout/images/page_bg.png" border="0" width="960"  
> height="799" alt="" style="position:absolute;left:0px;top:149px;"/>
> cannot be located when I request pages with params in the url.

This is a common error. Never use relative URLs. Use absolute URLs or,  
better yet, use the context binding prefix. Example below.

> Is there some way to reference the root context in my layout paths?

<img src="${context:/path/to/file.extension}"/>. This will work in all  
pages and components, no matter the folder your page is (their URL).

--
Thiago H. de Paula Figueiredo

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]