Uploaded image for project: 'Tiles'
  1. Tiles
  2. TILES-538

Pluggable debugging around rendering


    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.0.0
    • Component/s: tiles-api
    • Labels:
    • Flags:


      At finn.no we're using a custom TemplateAttributeRenderer (DispatchRenderer in tiles-3).

      One of the customisation we have is customised debugging around each template rendering. For us this customised debugging does:

      • print "<!-- start insertAttribute /template-name/ -->" before rendering
      • print "<!-- end insertAttribute /template-name/ /render-time-ms/ -->" after rendering
      • maintains a tree of templates rendered which is printed out as a comment at the bottom of the html, eg
        /WEB-INF/tiles/template/main_template.jsp (20ms)
        /WEB-INF/tiles/fragment/header.jsp (2ms)
        /WEB-INF/tiles/fragment/body.jsp (16ms)
        /WEB-INF/tiles/fragment/left_menu.jsp (6ms)
        /WEB-INF/tiles/fragment/content.jsp (10ms)
        /WEB-INF/tiles/fragment/footer.jsp (2ms)

      We find this useful for finding relevant jsps quickly, and for finding performance problems within the presentation layer in development and test environments. And I've seen something similar in other websites.

      Would it make sense to introduce such an api into DispatchRenderer so to make it possible to plug such debugging in rather than having to override the class. Simply overriding the class is not so simple when using the OptionsDispatchRenderer proposed in TILES-539.
      I'm not entirely sure myself so throwing this out there. One problem i can see if that this only works for the DispatchRenderer, although this is intended to be taken advantage of TilesContainerFactory.createTemplateAttributeRenderer(..) where it is specified as the default renderer.

      public class DispatchRenderer implements TypeDetectingRenderer {
          public interface DebugWrapper{
              DebugWrapper start(String template, Request request) throws IOException;
              DebugWrapper end();
              void handleIOException(IOException ex, Request request) throws IOException;
          private final DebugWrapper debugwrapper;
          public DispatchRenderer(){
              this.debugwrapper = new DummyDebugWrapper();
          public DispatchRenderer(DebugWrapper debugWrapper){
              this.debugwrapper = debugWrapper;
          /** {@inheritDoc} */
          public void render(String path, Request request) throws IOException {
              if (path == null) {
                  throw new CannotRenderException("Cannot dispatch a null path");
                  debugwrapper.start(path, request);
              }catch(IOException ex){
                  debugwrapper.handleIOException(ex, request);
          /** {@inheritDoc} */
          public boolean isRenderable(String path, Request request) {
              return path != null && path.startsWith("/");
          private static final class DummyDebugWrapper implements DebugWrapper{
              public DebugWrapper start(final String template, final Request request) throws IOException {
                  return this;
              public DebugWrapper end() {
                  return this;
              public void handleIOException(IOException ex, Request request) throws IOException {
                  throw ex;

      The handleIOException(..) also allows behaviour to be configurable against environment. For development and test we re-throw the IOException, but in production we ignore it and write a warning as a html comment into the response. This makes the "ignore" attribute to the template more of an assert rather than forced.




            • Assignee:
              michaelsembwever mck
              michaelsembwever mck
            • Votes:
              0 Vote for this issue
              0 Start watching this issue


              • Created: