1. Decorating RenderSupport and any MarkupRendererFilter

    I recently faced to some limitations with RenderSupport. I wanted to decorate it but I realized that this filter is not a service. What a shame, one of the most important Tapestry 5 service is not customisable…

    Really? No. There is a possibility to decorate RenderSupport, and in fact any of MarkupRendererFilter and Environment objects.

    How to achieve that?

    • Create a new RenderSupport implementation that will wrap the initial object. It’s just like we normally do when creating a decorator.
    • Create a MarkupRendererFilter that will pop RenderSupport from Environment
    • Create a the interceptor from the poped RenderSupport and push it into the Environment.
    • Contribute to MarkupRenderer’s ordered configuration and add your filter just after RenderSupport.
        public void contributeMarkupRenderer(OrderedConfiguration<MarkupRendererFilter> configuration)    {
            MarkupRendererFilter renderSupportInterceptor = new MarkupRendererFilter()
            {
                public void renderMarkup(MarkupWriter writer, MarkupRenderer renderer)
                {
                    RenderSupport delegate = (RenderSupport) environment.pop(RenderSupport.class);
                    RenderSupport interceptor = new RenderSupportInterceptor(delegate);
    
                    environment.push(RenderSupport.class, interceptor);
                    renderer.renderMarkup(writer);
                }
            };
            configuration.add("RenderSupportDecorator", renderSupportInterceptor, "after:RenderSupport", "before:ClientBehaviorSupport",
                    "before:InjectDefaultStyleheet", "before:Heartbeat");
        }
    

No Comments »

RSS for comments - TrackBack URL

no comments yet.

Leave a comment

Spam Protection by WP-SpamFree