You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Dave Greggory <da...@yahoo.com> on 2009/04/09 20:23:38 UTC

[t5.1.0.2] Migration problem as LinkFactory is no longer present

We needed to contribute a custom version of LinkFactory to meet a business need. I realize that it was internal and was subject to change, but now that there is no LinkFactory present in 5.1 I would like some help figuring out how to implement the same functionality.

We need to be able to specify custom URLs for Tapestry pages (multiple URLs can go to the same Page and sometimes the same URL can go to different tapestry Pages). Couldn't really achieve it using activation context as the complete url needed to be customizable. So we implemented a Dispatcher to handle it, but later on found out that we have override the LinkFactory.createPageRenderLink(..) functionality to get forms working properly (action url for forms were not rendering as the custom url without the LinkFactory).

The change we made to LinkFactory is given below. How do we do the same in 5.1?

  public Link createPageRenderLink(Page page, boolean override, Object... pageActivationContext)
  {
      String logicalPageName = page.getLogicalName();

      // When override is true, we use the activation context even if empty.
      Object[] context = (override || pageActivationContext.length != 0)
                         ? pageActivationContext
                         : contextCollector.collectPageActivationContext(page);
      InvocationTarget target = new PageRenderTarget(logicalPageName);

      // ------------------------------- our change (begin) ----------------------------------------------
      String pageUrl = (String) request.getAttribute(OurConstants.PAGE_URL.id());
      if (!StringUtils.isBlank(pageUrl))
      {
        while (pageUrl.startsWith("/"))
        {
          pageUrl = pageUrl.substring(1);
        }
        target = new OpaqueConstantTarget(pageUrl);
      }
      // ------------------------------- our change (end) ----------------------------------------------

      ComponentInvocation invocation = new ComponentInvocationImpl(contextPathEncoder, target, null, context, false);
      String baseURL = requestSecurityManager.getBaseURL(page);
      Link link = new LinkImpl(response, optimizer, baseURL, request.getContextPath(), invocation);
      componentInvocationMap.store(link, invocation);

      for (LinkFactoryListener listener : listeners)
          listener.createdPageRenderLink(link);

      return link;
  }


      

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


Re: [t5.1.0.2] Migration problem as LinkFactory is no longer present

Posted by Dave Greggory <da...@yahoo.com>.
Hi Andy,

Thanks for the suggestion, but I'm not quite sure what you're doing when you're advising the ComponentEventLinkEncoder. Since the internals are much more different, I'm not sure how to advise the createPageRenderLink method. If you don't mind, can you provide details of what you're doing inside MethodAdviceCreatePageRenderLink/MethodAdviceDecodePageRenderRequest?

I'm gonna check out URL Rewriting as well.

Thanks,
Dave



----- Original Message ----
From: "Blower, Andy" <An...@proquest.co.uk>
To: Tapestry users <us...@tapestry.apache.org>
Sent: Thursday, April 9, 2009 2:53:19 PM
Subject: RE: [t5.1.0.2] Migration problem as LinkFactory is no longer present

If you want to do the equivalent in 5.1 then you'll need to extend ComponentEventLinkEncoderImpl and override any methods you want to change. Alternatively (since the decoding is now in here rather than in the Dispatcher) you can use service advice which is what I did. Check out the recent thread I started called "T5.1 URL Rewriting", you might even find that URL Rewriting will do what you need.

If you do go the advice route, then you'll need something like this the code below in your module. This add advice to the createPageRenderLink() & decodePageRenderRequest() methods handled by the MethodAdviceCreatePageRenderLink & MethodAdviceDecodePageRenderRequest method advice classes I wrote. The biggest thing to note is the * at the beginning of the Match annotation - without this it wouldn't work, but I have no idea why. If anyone can tell me why I need the * I'd be very interested.

Cheers,

Andy.

@Match("*ComponentEventLinkEncoder")
public static void advisePQSiteHandling(
            ComponentClassResolver componentClassResolver, 
            ContextPathEncoder contextPathEncoder, 
            Response response, 
            MethodAdviceReceiver receiver) throws Exception
{
       Method createPageRenderLinkMethod = ComponentEventLinkEncoder.class.getMethod("createPageRenderLink", PageRenderRequestParameters.class);
       receiver.adviseMethod(createPageRenderLinkMethod, new MethodAdviceCreatePageRenderLink(response));
        
       Method decodePageRenderRequestMethod = ComponentEventLinkEncoder.class.getMethod("decodePageRenderRequest", Request.class);
       receiver.adviseMethod(decodePageRenderRequestMethod, new MethodAdviceDecodePageRenderRequest(componentClassResolver, contextPathEncoder));
}


      


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


RE: [t5.1.0.2] Migration problem as LinkFactory is no longer present

Posted by "Blower, Andy" <An...@proquest.co.uk>.
If you want to do the equivalent in 5.1 then you'll need to extend ComponentEventLinkEncoderImpl and override any methods you want to change. Alternatively (since the decoding is now in here rather than in the Dispatcher) you can use service advice which is what I did. Check out the recent thread I started called "T5.1 URL Rewriting", you might even find that URL Rewriting will do what you need.

If you do go the advice route, then you'll need something like this the code below in your module. This add advice to the createPageRenderLink() & decodePageRenderRequest() methods handled by the MethodAdviceCreatePageRenderLink & MethodAdviceDecodePageRenderRequest method advice classes I wrote. The biggest thing to note is the * at the beginning of the Match annotation - without this it wouldn't work, but I have no idea why. If anyone can tell me why I need the * I'd be very interested.

Cheers,

Andy.

@Match("*ComponentEventLinkEncoder")
public static void advisePQSiteHandling(
			ComponentClassResolver componentClassResolver, 
			ContextPathEncoder contextPathEncoder, 
			Response response, 
			MethodAdviceReceiver receiver) throws Exception
{
       Method createPageRenderLinkMethod = ComponentEventLinkEncoder.class.getMethod("createPageRenderLink", PageRenderRequestParameters.class);
       receiver.adviseMethod(createPageRenderLinkMethod, new MethodAdviceCreatePageRenderLink(response));
		
       Method decodePageRenderRequestMethod = ComponentEventLinkEncoder.class.getMethod("decodePageRenderRequest", Request.class);
       receiver.adviseMethod(decodePageRenderRequestMethod, new MethodAdviceDecodePageRenderRequest(componentClassResolver, contextPathEncoder));
}
	

> -----Original Message-----
> From: Dave Greggory [mailto:davegreggory@yahoo.com]
> Sent: 09 April 2009 19:24
> To: Tapestry users
> Subject: [t5.1.0.2] Migration problem as LinkFactory is no longer
> present
> 
> 
> We needed to contribute a custom version of LinkFactory to meet a
> business need. I realize that it was internal and was subject to
> change, but now that there is no LinkFactory present in 5.1 I would
> like some help figuring out how to implement the same functionality.
> 
> We need to be able to specify custom URLs for Tapestry pages (multiple
> URLs can go to the same Page and sometimes the same URL can go to
> different tapestry Pages). Couldn't really achieve it using activation
> context as the complete url needed to be customizable. So we
> implemented a Dispatcher to handle it, but later on found out that we
> have override the LinkFactory.createPageRenderLink(..) functionality to
> get forms working properly (action url for forms were not rendering as
> the custom url without the LinkFactory).
> 
> The change we made to LinkFactory is given below. How do we do the same
> in 5.1?
> 
>   public Link createPageRenderLink(Page page, boolean override,
> Object... pageActivationContext)
>   {
>       String logicalPageName = page.getLogicalName();
> 
>       // When override is true, we use the activation context even if
> empty.
>       Object[] context = (override || pageActivationContext.length !=
> 0)
>                          ? pageActivationContext
>                          :
> contextCollector.collectPageActivationContext(page);
>       InvocationTarget target = new PageRenderTarget(logicalPageName);
> 
>       // ------------------------------- our change (begin) -----------
> -----------------------------------
>       String pageUrl = (String)
> request.getAttribute(OurConstants.PAGE_URL.id());
>       if (!StringUtils.isBlank(pageUrl))
>       {
>         while (pageUrl.startsWith("/"))
>         {
>           pageUrl = pageUrl.substring(1);
>         }
>         target = new OpaqueConstantTarget(pageUrl);
>       }
>       // ------------------------------- our change (end) -------------
> ---------------------------------
> 
>       ComponentInvocation invocation = new
> ComponentInvocationImpl(contextPathEncoder, target, null, context,
> false);
>       String baseURL = requestSecurityManager.getBaseURL(page);
>       Link link = new LinkImpl(response, optimizer, baseURL,
> request.getContextPath(), invocation);
>       componentInvocationMap.store(link, invocation);
> 
>       for (LinkFactoryListener listener : listeners)
>           listener.createdPageRenderLink(link);
> 
>       return link;
>   }
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 



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


Re: [t5.1.0.2] Migration problem as LinkFactory is no longer present

Posted by Dave Greggory <da...@yahoo.com>.
I wasn't actually aware of the URL rewriting feature was intended for this purpose. I'm gonna check it out. Do you plan to release a 5.1.0.x release of your changes shortly?

Dave



----- Original Message ----
From: Robert Zeigler <ro...@scazdl.org>
To: Tapestry users <us...@tapestry.apache.org>
Sent: Thursday, April 9, 2009 3:02:27 PM
Subject: Re: [t5.1.0.2] Migration problem as LinkFactory is no longer present

Hi Dave,

I should be committing some changes to the new URL Rewriting support shortly (updating documentation at the moment); I'll be very curious to see if the api changes (note: this is an "alpha" feature, still subject to api change until 5.1 is declared "final") will allow you to do what you need.
Among other things, the rewriter rules are now provided a context, and a chance to declare whether they want to operate on incoming requests, outgoing "requests" (link urls), or both.
The context provides information as to whether the processing is for incoming/outgoing, and for "outgoing", it provides access to the PageRenderRequestParameters and ComponentEventRequestParameters objects (for page links and component event links, respectively). So you can easily get at the page name, event name, event id, etc. when you're rewriting links.  I'm not 100% satisfied with the naming; and I'm still deciding on whether directly exposing the request parameter objects is the "right thing" to do.  But I'll commit it to give people a chance to give feedback.

Robert

On Apr 9, 2009, at 4/91:23 PM , Dave Greggory wrote:

> 
> We needed to contribute a custom version of LinkFactory to meet a business need. I realize that it was internal and was subject to change, but now that there is no LinkFactory present in 5.1 I would like some help figuring out how to implement the same functionality.
> 
> We need to be able to specify custom URLs for Tapestry pages (multiple URLs can go to the same Page and sometimes the same URL can go to different tapestry Pages). Couldn't really achieve it using activation context as the complete url needed to be customizable. So we implemented a Dispatcher to handle it, but later on found out that we have override the LinkFactory.createPageRenderLink(..) functionality to get forms working properly (action url for forms were not rendering as the custom url without the LinkFactory).
> 
> The change we made to LinkFactory is given below. How do we do the same in 5.1?
> 
>  public Link createPageRenderLink(Page page, boolean override, Object... pageActivationContext)
>  {
>      String logicalPageName = page.getLogicalName();
> 
>      // When override is true, we use the activation context even if empty.
>      Object[] context = (override || pageActivationContext.length != 0)
>                         ? pageActivationContext
>                         : contextCollector.collectPageActivationContext(page);
>      InvocationTarget target = new PageRenderTarget(logicalPageName);
> 
>      // ------------------------------- our change (begin) ----------------------------------------------
>      String pageUrl = (String) request.getAttribute(OurConstants.PAGE_URL.id());
>      if (!StringUtils.isBlank(pageUrl))
>      {
>        while (pageUrl.startsWith("/"))
>        {
>          pageUrl = pageUrl.substring(1);
>        }
>        target = new OpaqueConstantTarget(pageUrl);
>      }
>      // ------------------------------- our change (end) ----------------------------------------------
> 
>      ComponentInvocation invocation = new ComponentInvocationImpl(contextPathEncoder, target, null, context, false);
>      String baseURL = requestSecurityManager.getBaseURL(page);
>      Link link = new LinkImpl(response, optimizer, baseURL, request.getContextPath(), invocation);
>      componentInvocationMap.store(link, invocation);
> 
>      for (LinkFactoryListener listener : listeners)
>          listener.createdPageRenderLink(link);
> 
>      return link;
>  }
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org


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


      


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


Re: [t5.1.0.2] Migration problem as LinkFactory is no longer present

Posted by Robert Zeigler <ro...@scazdl.org>.
Hi Dave,

I should be committing some changes to the new URL Rewriting support  
shortly (updating documentation at the moment); I'll be very curious  
to see if the api changes (note: this is an "alpha" feature, still  
subject to api change until 5.1 is declared "final") will allow you to  
do what you need.
Among other things, the rewriter rules are now provided a context, and  
a chance to declare whether they want to operate on incoming requests,  
outgoing "requests" (link urls), or both.
The context provides information as to whether the processing is for  
incoming/outgoing, and for "outgoing", it provides access to the  
PageRenderRequestParameters and ComponentEventRequestParameters  
objects (for page links and component event links, respectively). So  
you can easily get at the page name, event name, event id, etc. when  
you're rewriting links.  I'm not 100% satisfied with the naming; and  
I'm still deciding on whether directly exposing the request parameter  
objects is the "right thing" to do.  But I'll commit it to give people  
a chance to give feedback.

Robert

On Apr 9, 2009, at 4/91:23 PM , Dave Greggory wrote:

>
> We needed to contribute a custom version of LinkFactory to meet a  
> business need. I realize that it was internal and was subject to  
> change, but now that there is no LinkFactory present in 5.1 I would  
> like some help figuring out how to implement the same functionality.
>
> We need to be able to specify custom URLs for Tapestry pages  
> (multiple URLs can go to the same Page and sometimes the same URL  
> can go to different tapestry Pages). Couldn't really achieve it  
> using activation context as the complete url needed to be  
> customizable. So we implemented a Dispatcher to handle it, but later  
> on found out that we have override the  
> LinkFactory.createPageRenderLink(..) functionality to get forms  
> working properly (action url for forms were not rendering as the  
> custom url without the LinkFactory).
>
> The change we made to LinkFactory is given below. How do we do the  
> same in 5.1?
>
>  public Link createPageRenderLink(Page page, boolean override,  
> Object... pageActivationContext)
>  {
>      String logicalPageName = page.getLogicalName();
>
>      // When override is true, we use the activation context even if  
> empty.
>      Object[] context = (override || pageActivationContext.length !=  
> 0)
>                         ? pageActivationContext
>                         :  
> contextCollector.collectPageActivationContext(page);
>      InvocationTarget target = new PageRenderTarget(logicalPageName);
>
>      // ------------------------------- our change (begin)  
> ----------------------------------------------
>      String pageUrl = (String)  
> request.getAttribute(OurConstants.PAGE_URL.id());
>      if (!StringUtils.isBlank(pageUrl))
>      {
>        while (pageUrl.startsWith("/"))
>        {
>          pageUrl = pageUrl.substring(1);
>        }
>        target = new OpaqueConstantTarget(pageUrl);
>      }
>      // ------------------------------- our change (end)  
> ----------------------------------------------
>
>      ComponentInvocation invocation = new  
> ComponentInvocationImpl(contextPathEncoder, target, null, context,  
> false);
>      String baseURL = requestSecurityManager.getBaseURL(page);
>      Link link = new LinkImpl(response, optimizer, baseURL,  
> request.getContextPath(), invocation);
>      componentInvocationMap.store(link, invocation);
>
>      for (LinkFactoryListener listener : listeners)
>          listener.createdPageRenderLink(link);
>
>      return link;
>  }
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org


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