Class OptionsRenderer

  • All Implemented Interfaces:
    org.apache.tiles.request.render.Renderer

    public final class OptionsRenderer
    extends java.lang.Object
    implements org.apache.tiles.request.render.Renderer
    Provides a custom "options" syntax for attributes. The first option that can be rendered is. Comes from The Ultimate View article.

    Actual rendering is delegated to the TypeDetectingRenderer that's supplied in the constructor.

    For example: "/WEB-INF/tiles/fragments/${options[myoptions]}/content.jsp" given the myptions list-attribute is defined like:

            <put-list-attribute name="myoptions">
                <add-list-attribute>
                    <add-attribute value="car"/>
                    <add-attribute value="vechile"/>
                    <add-attribute value="advert"/>
                </add-list-attribute>
            </put-list-attribute>
       
    will look for content.jsp
    first in "/WEB-INF/tiles/fragments/car/" then
    second in "/WEB-INF/tiles/fragments/vechile/" and
    last in "/WEB-INF/tiles/fragments/advert".

    Currently only supports one occurrance of such an "option" pattern in the attribute's value.

    Limitation: "looking" for templates is implemented using applicationContext.getResource(..) therefore the option values in the options list need to be visible as applicationResources.

    The attribute found and rendered is cached so to improve performance on subsequent lookups. The default cache time-to-live is 300000L, specified by DEFAULT_CACHE_LIFE. It can be customised by setting the system property , see CACHE_LIFE_PROPERTY. Setting it to zero will disable the cache.

    • Constructor Summary

      Constructors 
      Constructor Description
      OptionsRenderer​(org.apache.tiles.request.ApplicationContext applicationContext, org.apache.tiles.request.render.Renderer renderer)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean isRenderable​(java.lang.String path, org.apache.tiles.request.Request request)  
      void render​(java.lang.String path, org.apache.tiles.request.Request request)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • CACHE_LIFE_PROPERTY

        public static final java.lang.String CACHE_LIFE_PROPERTY
      • OPTIONS_PATTERN

        public static final java.util.regex.Pattern OPTIONS_PATTERN
    • Constructor Detail

      • OptionsRenderer

        public OptionsRenderer​(org.apache.tiles.request.ApplicationContext applicationContext,
                               org.apache.tiles.request.render.Renderer renderer)
    • Method Detail

      • isRenderable

        public boolean isRenderable​(java.lang.String path,
                                    org.apache.tiles.request.Request request)
        Specified by:
        isRenderable in interface org.apache.tiles.request.render.Renderer
      • render

        public void render​(java.lang.String path,
                           org.apache.tiles.request.Request request)
                    throws java.io.IOException
        Specified by:
        render in interface org.apache.tiles.request.render.Renderer
        Throws:
        java.io.IOException