You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Alan Chaney <al...@compulsivecreative.com> on 2009/10/02 23:15:56 UTC

Processing "resttful" requests

Sorry, more newbie questions.

I want to have URLs following a "restful" form, eg:

<website>/stuff/xxx/yyy

where I have a page Stuff which processes xxx/yyy as a 'request 
parameter' and dynamically generates appropriate content.

I've got a class Stuff.java and the docs say:

Page render requests are requests to render a particular page. Such 
requests may include additional elements on the path, which will be 
treated as activation context (generally speaking, the primary key of 
some related entity object), allowing the page to reconstruct the state 
it will need to succesfully render itself.

The event handler method for the activate event may return a value; this 
is treated the same as the return value from a component action request; 
typically this will result in a redirect to another page. In this way, 
the activate event can perform simple validation at the page level ("can 
the user see this page?").

Page render URLs consist of the logical name of the page plus additional 
path elements for the activation context. The dispatcher here strips 
terms off of the path until it finds a known page name. Thus, 
"/mypage/27" would look first for a page whose name was "mypage/27", 
then look for a page name "mypage". Assuming the second search was 
succesful, the page would be activated with the context "27". If no 
logical page name can be identified, control passes to the next dispatcher.

This seems to imply to me that if I have a method

void onActivate(String param)

then param should contain xxx/yyy and I should be able to act on it 
accordingly.

And in fact it does. But then the same method is called again with the 
value "layout" and the page redisplays. "layout" is the name of my 
Layout (well, doh!) and when it redisplays the logo which is part of the 
layout.tml file disappears...


If I just use the path <website>/stuff then I don't get the 2nd call to 
onActivate.

What am I missing here? Why is my layout template name turning up?

Thanks in advance

Alan Chaney




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


Re: Processing "resttful" requests

Posted by Alan Chaney <al...@compulsivecreative.com>.

Thiago H. de Paula Figueiredo wrote:

> 
> Very Tapestry-y. :)
> 
> 
> Don't use relative paths to CSS/JavaScript/images/anything. By the way, 
> the recommended way of doing it is using ${asset:} expressions 
> (${asset:context/images/image.jpg, for example). This is the most common 

> cause for problems like yours.

Yes, in fact the problem of the page redisplaying and the image not 
being displayed was exactly this. I moved the image file to 
classpath:<project.stuff>/images/logo.gif and changed the href in the 
tml file to ${asset:images/logo.gif} and it all started to work.

> 
> Another advice: instead of onActivate(String s) or onActivate(String s1, 
> String s2), the best way to receive the context parameters is to have a 
> single onActivate(EventContext context) method. It will be called 
> regardless of the number of parameters and the EventContext variable 
> will give you the number of parameters and their values.
Yes, again. Did this, understood what was happening with the image and 
saw the benefit of this approach..

Once again, thanks Thiago!

Regards

Alan Chaney



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


Re: Processing "resttful" requests

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Fri, 02 Oct 2009 18:15:56 -0300, Alan Chaney  
<al...@compulsivecreative.com> escreveu:

> Sorry, more newbie questions.
> I want to have URLs following a "restful" form, eg:
> <website>/stuff/xxx/yyy

Very Tapestry-y. :)

> And in fact it does. But then the same method is called again with the  
> value "layout" and the page redisplays. "layout" is the name of my  
> Layout (well, doh!) and when it redisplays the logo which is part of the  
> layout.tml file disappears...

Don't use relative paths to CSS/JavaScript/images/anything. By the way,  
the recommended way of doing it is using ${asset:} expressions  
(${asset:context/images/image.jpg, for example). This is the most common  
cause for problems like yours.

Another advice: instead of onActivate(String s) or onActivate(String s1,  
String s2), the best way to receive the context parameters is to have a  
single onActivate(EventContext context) method. It will be called  
regardless of the number of parameters and the EventContext variable will  
give you the number of parameters and their values.

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

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