Announcement Announcement Module
Collapse
No announcement yet.
Tiles with wildcards Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Tiles with wildcards

    One problem with Tiles is that you can end up with lots of boiler-plate XML config. This is certainly true when using Tiles with Roo, since Roo web scaffolding generates view.xml files for each entity that it manages.

    Tiles wildcard pattern matching templates could be used to eliminate most (or all) of the views.xml files. I tried this on a sample Roo app and it seems to work fine.

    webapp/WEB-INF/layouts/layouts.xml

    Code:
    <tiles-definitions>
      <definition name="default" template="/WEB-INF/layouts/default.jspx">
        <put-attribute name="header" value="/WEB-INF/views/header.jspx" />
        <put-attribute name="menu" value="/WEB-INF/views/menu.jspx" />
        <put-attribute name="footer" value="/WEB-INF/views/footer.jspx" />
      </definition>
    
      <definition name="*/*" extends="default">
        <put-attribute name="body" value="/WEB-INF/views/{1}/{2}.jspx"/>
      </definition>
    
      <definition name="public" template="/WEB-INF/layouts/default.jspx">
        <put-attribute name="header" value="/WEB-INF/views/header.jspx" />
        <put-attribute name="footer" value="/WEB-INF/views/footer.jspx" />
      </definition>
    
      <definition name="*" extends="public">
        <put-attribute name="body" value="/WEB-INF/views/{1}.jspx"/>
      </definition>
    </tiles-definitions>
    The second tiles definition here (name="*/*") should replace all the views.xml files that are generated for each entity (for example an entire file like this one is replaced by that one wildcard pattern):

    webapp/WEB-INF/views/pizzas/views.xml

    Code:
    <tiles-definitions>
      <definition extends="default" name="pizzas/list">
        <put-attribute name="body" value="/WEB-INF/views/pizzas/list.jspx"/>
      </definition>
      <definition extends="default" name="pizzas/show">
        <put-attribute name="body" value="/WEB-INF/views/pizzas/show.jspx"/>
      </definition>
      <definition extends="default" name="pizzas/create">
        <put-attribute name="body" value="/WEB-INF/views/pizzas/create.jspx"/>
      </definition>
      <definition extends="default" name="pizzas/update">
        <put-attribute name="body" value="/WEB-INF/views/pizzas/update.jspx"/>
      </definition>
    </tiles-definitions>
    Likewise, the fourth definition (name="*") replaces all the definitions in webapp/WEB-INF/views/views.xml.

    Is there a downside to using wildcard patterns for Tiles defs instead of generating (and maintaining) all those views.xml files?

  • #2
    Is there a downside to using wildcard patterns for Tiles defs instead of generating (and maintaining) all those views.xml files?
    If it's possible to override those wildcards as necessary, I'd say there's no downside. How are the tiles definitions resolved, is it top-to-bottom, most-to-least specific, or what?

    Comment

    Working...
    X