I found a way to do it by implementing a PageRenderRequestFilter. However
this is a bit tricky, since it requires a "User" page defined for it to work
(even if it is not used by the app), because this filter is only called if
_componentClassResolver.isPageName(pageName) is successful (cf
PageRenderDispatcher source code).

For my use, it would be best for PageRenderDispatcher to be independent from
ComponentClassResolver, and PageRenderRequestHandler dependent on it. To me
it makes more sense if PageRenderRequestHandler (and Filter) class knows if
it can handle a given logicalPageName or not, rather than directly use the
ComponentClassResolver in the dispatcher.

What do you think?

Fabien.

PS: My current solution is the following

   public PageRenderRequestFilter
buildNewsbeefPageRenderRequestFilter(final Log log) {
   return new PageRenderRequestFilter() {

       public ActionResponseGenerator handle(String logicalPageName,
String[] context,
           PageRenderRequestHandler handler) {
       if (log.isDebugEnabled()) {
           log.debug("pagerenderrequestfilter, logicalPageName=" +
logicalPageName
               + ",context="+Arrays.toString(context));
       }
       if (logicalPageName.equalsIgnoreCase("user") && context.length >= 2)
{
           //this is a user specific page
           // /user/userId/page/ddddd/nnnn becomes
/userpages/Page/dddd/nnnn/user/userId
           if (context[1].length() > 0) {
           String newPageName = Character.toUpperCase(context[1].charAt(0))
               + context[1].substring(1);
           newPageName = "userpages/" + newPageName;
           String[] newContext = new String[context.length];
           for (int i=2; i<context.length;i++) {
               newContext[i-2] = context[i];
           }
           newContext[context.length-2] = logicalPageName;
           newContext[context.length-1] = context[0];
           return handler.handle(newPageName, newContext);
           }
       }
       return handler.handle(logicalPageName, context);
       }
   };
   }

On 7/13/07, Fabien Le Floc'h <[EMAIL PROTECTED]> wrote:

Hi All,
I am new to Tapestry and would like to have a particular mapping for some
pages. For example, I would like that a call to
/user/MyUserName/viewSomething/withThisParameter maps to a page called
ViewSomething, where a user field would be initialized with MyUserName.

Now I can easily achieve similar goal using the url
/viewSomething/MyUserName/withThisParameter by using onActivate(x,y). But
the url does not have the same meaning and is less logical. As a concrete
example, try /tag/billgates/microsoft, it is not obvious what this is, but
/user/billgates/tag/microsoft is easy to guess.

So I would like to do a filter that intercepts the request and if it
starts with /user, get the page let's say in userpages packages instead of
pages package, and then pass the parameter after user/ and before /pageName
to it. It is quite simple to do using regular ServletFilter, how do i do
that with Tapestry Pages?

Regards,

Fabien.

PS: note that I don't expect this to be automatically done by T5, but I
hope there would be a simple programmatic way to do that.

Reply via email to