java - Tapestry5 : URL Re-writing : Pass parameters to transformPageRenderLink method -


i upgrading tapestry 5.2.4 5.3.8 , stuck @ re-implementing url re-writing part.

in application user account can have multiple data stores. user can have same page of different stores active @ same time. hence need put storeid in page links , event links urls. done follows.

i register mylinktransformerclass in appmodule follows.

    @contribute(pagerenderlinktransformer.class)     @primary     public static void provideurlrewriting( orderedconfiguration<pagerenderlinktransformer> configuration){          configuration.addinstance(           "faces", mylinktransformer.class);     } 

following mylinktransformer class implements pagerenderlinktransformer

public pagerenderrequestparameters decodepagerenderrequest(                   request request) {        // incoming requests - remove store id url ,        // save request attribute        string path = request.getpath();       if (path.equals("/")) {              // redirect accounts page              return new pagerenderrequestparameters("account", new emptyeventcontext(), false);          }          else {              string start = path.split("/")[1];              if (!ignoredrewriteset.contains(start) && !start.startswith("account")) {                  string storepath = path.substring(1).substring(path.indexof("/"));                  int idx = storepath.indexof("/");                  if (idx < 0) idx = storepath.length();                  string storeid = storepath.substring(0, idx).trim();                  requesthelper.setstoreid(request, storeid);                  eventcontext urleventcontext = new urleventcontext(contextvalueencoder, new string[]{storeid});                  eventcontext arrayeventcontext = new arrayeventcontext(typecoercer, "foo");                      return new pagerenderrequestparameters(storepath.substring(idx), arrayeventcontext, false);                  //return new pagerenderrequestparameters(storepath.substring(idx), new emptyeventcontext(), false);              }      }        return null;     }     public link transformpagerenderlink(          link defaultlink,          pagerenderrequestparameters parameters) {        // outgoing requests- want access store id        // stored in request class of tapestry attribute ,        // add url        return null;    } 

so, idea remove storeid url in decodepagerenderrequest method , save in request class of tapestry attribute. , while creating outgoing urls of page link , event link, want access storeid saved in request , inject url rendered in method transformpagerenderlink.

but don't know how pass parameters transformpagerenderlink method or access request instance there.

i following http://blog.tapestry5.de/index.php/2010/09/06/new-url-rewriting-api/ example. new url rewriting, appreciated.

you interested in modecomponenteventlinkencoder here. removes "mode" url , puts onto environment before passing on normal tapestry url processing.

it's 2 way process "mode" included in links generated on page.

note: applied decorator here


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -