This is the same question on stackoverflow.
http://stackoverflow.com/questions/30259617/tapestry5-url-re-writing-pass-parameters-to-transformpagerenderlink-method
I am upgrading tapestry from 5.2.4 to 5.3.8 and am stuck at
re-implementing the URL re-writing part.
In my application a user account can have multiple data stores. User can
have same page of different stores active at the same time. Hence I need
to put the storeId in page links and event links URLs. So What is done
is as follows.
I register MyLinkTransformerClass in AppModule as follows.
@Contribute(PageRenderLinkTransformer.class)
@Primary
public static void provideURLRewriting(
OrderedConfiguration<PageRenderLinkTransformer> configuration){
configuration.addInstance(
"Faces", MyLinkTransformer.class);
}
Following is the MyLinkTransformer class which implements
PageRenderLinkTransformer
public PageRenderRequestParameters decodePageRenderRequest(
Request request) {
// for incoming requests - remove the store id from URL and
// save into Request as an attribute
String path = request.getPath();
if (path.equals("/")) {
// Redirect to 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) {
// for outgoing requests- This is where I want to access the store
Id
// which is stored in Request class of Tapestry as an attribute
and
// add it to the URL
return null;
}
So, the idea is to remove storeId from URL in decodePageRenderRequest
method and save it in the Request class of Tapestry as an attribute. And
while creating outgoing URLs of page link and event link, I want to
access the storeId which was saved in Request and inject it to the URL
which will be rendered in method transformPageRenderLink.
But I don't know how to pass parameters to transformPageRenderLink
method or access Request instance there.
I am following
http://blog.tapestry5.de/index.php/2010/09/06/new-url-rewriting-api/
example.
I am new to URL Rewriting, any help with this will be appreciated.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org