I'm not 100% but I think that you might need to decorate the ComponentEventLinkEncoder instead of contributing a URLRewriter as I *think* that URLRewriters can't decorate the result, they can only short circut out of the chain.
I think you will need to do something like this: public class AppModule { public ComponentEventLinkEncoder decorateComponentEventLinkEncoder(ComponentEventLinkEncoder delegate, Environemnt environment) { return new ModeComponentEventLinkEncoder(delegate, environment); } } public class ModeComponentEventLinkEncoder { private Envirnoment environment; private ComponentEventLinkEncoder delegate; // constructor public Link createPageRenderLink(PageRenderRequestParameters parameters) { return transform(delegate.createPageRenderLink(parameters)); } public Link createComponentEventLink(ComponentEventRequestParameters parameters, boolean forForm) { return transform(delegate.createComponentEventLink(parameters, forForm)); } public ComponentEventRequestParameters decodeComponentEventRequest(Request request) { return delegate.decodeComponentEventRequest(transform(request)); } public PageRenderRequestParameters decodePageRenderRequest(Request request) { return delegate.decodePageRenderRequest(transform(request)); } protected Link transform(Link link) { Mode mode = environment.peek(Mode.class); String newBasePath = addModeToPath(link.getBasePath(), mode); return link.copyWithBasePath(newBasePath); } protected Request transform(Request request) { String mode = getModeFromRequest(request.getPath()); envirnoment.push(Mode.class, new ModeImpl(mode)); String newPath = removeModeFromPath(request.getPath()); // RequestWrapper implements Request and overrides getPath() return new RequestWrapper(request, newPath); } } On Thursday, 29 March 2012, Juan Alba <juan.a...@condortech.com.ar> wrote: > Thanks Lance Again. > > I have just been being reading the article you share with me and I realized > that is for tapestry 5.2.0. I am using 5.1.0.5, so I will have to use the * > URLRewriter* service (Can't update to 5.2.0). I have no idea how this work > either, do you think that I will be able to do something similar with this > service? > > Thanks in advance. > > > On Wed, Mar 28, 2012 at 1:08 PM, Lance Java <lance.j...@googlemail.com >wrote: > >> Great, if Tapestry is the only thing rendering your links then it will all >> work. >> >> By overriding the PageRenderLinkTransformer you are intercepting both link >> creation and URL decoding so you are covering the whole flow. >> >> On Wednesday, 28 March 2012, Juan Alba <juan.a...@condortech.com.ar> >> wrote: >> > Thanks Again Lance. >> > >> > On Wed, Mar 28, 2012 at 12:10 PM, Lance Java <lance.j...@googlemail.com >> >wrote: >> > >> >> I was assuming that all of your links were rendered by Tapestry (eg >> >> EventLink and ActionLink). If this was the case then it *should* just >> work. >> >> >> > >> > You are assuming well. I am using ActionLinks. >> > Right now, When you click a link I am doing: >> > "return Page.class;" >> > But as far as I understood, now I will have to do something like: >> > *@Inject Enviroment* >> > >> > and instead of return do some stuff like: >> > >> > *return(pageRender.createPageRenderLink(FBAssociationPage.class)+ >> > ".facebookloginlink");* >> > >> > adding the getMode() somewhere in there... >> > >> > So it seems I am not understanding very well how to use the @Enviroment. >> Or >> > this is what I have to do? >> > >> > Thanks. >> > >> > >> >> On Wednesday, 28 March 2012, Juan Alba <juan.a...@condortech.com.ar> >> >> wrote: >> >> > First of all, thanks again Lance! >> >> > >> >> > >> >> > >> >> > On Wed, Mar 28, 2012 at 11:25 AM, Lance Java < >> lance.j...@googlemail.com >> >> >wrote: >> >> > >> >> >> Perhaps this would work >> >> >> >> >> >> Create an environmental object called Mode >> >> >> >> >> >> public interface Mode { >> >> >> public String getMode(); // facebook or normal >> >> >> } >> >> >> >> >> >> Use tapestry's URL rewriting to rewrite http://myapp/facebook/pageto >> >> >> http://myapp/page (see >> >> >> http://blog.tapestry5.de/index.php/2010/09/06/new-url-rewriting-api/ >> ) >> >> >> >> >> >> As the URL is rewritten, it pushes a mode onto the environment >> (either >> >> >> "facebook" or "normal") >> >> >> >> >> >> @Inject >> >> >> Environment environment >> >> >> >> >> >> String mode = getModeFromURL(); >> >> >> environment.push(Mode.class, new ModeImpl(mode)); >> >> >> >> >> > >> >> > This is great and I think that I'd got it. >> >> > >> >> > The problem is with this second part: >> >> > >> >> >> When rendering links, use Environment.peek() to get the Mode from the >> >> >> environment and add the mode to each link URL if necessary. >> >> >> >> >> >> Components and Pages can then use the @Environmental annotation to >> >> inject >> >> >> the mode to determine which styles to include >> >> >> >> >> >> Then you get normal browsers to access http://myapp/page and >> facebook >> >> to >> >> >> access http://myapp/facebook/page >> >> >> >> >> >> >> >> > My web app is using a lot of webLibs (almost one per section). If I do >> >> > this, I will have to change all the web app, and all the web libs to >> >> > build the links correctly? It seems to be a huge re-factoring. >> >