tiles.xml: Definitions and Inheritance

Harry · 23 Sep 2026 · 1 views
Log in to track your progress and mark lessons complete.

Base Definition

<tiles-definitions>
  <definition name="base" template="/WEB-INF/views/layout.jsp">
    <put-attribute name="title" value="GroovyGrails Tiles Demo"/>
    <put-attribute name="header" value="/WEB-INF/views/header.jsp"/>
    <put-attribute name="menu" value="/WEB-INF/views/menu.jsp"/>
    <put-attribute name="body" value=""/>
    <put-attribute name="footer" value="/WEB-INF/views/footer.jsp"/>
  </definition>

  <definition name="home" extends="base">
    <put-attribute name="title" value="Book Catalog"/>
    <put-attribute name="body" value="/WEB-INF/views/home.jsp"/>
  </definition>
</tiles-definitions>

Inheritance Wins

home extends base and overrides only title and body. Twenty pages share one layout; each page is two lines of XML.

put-attribute Flavours

  • value - a JSP path or literal string.
  • expression - OGNL/EL evaluated at render.
  • cascaded - pass attributes down nested definitions.

Key Points

  • One base definition, many thin children.
  • Controller returns the definition name, never a JSP path.
  • Keep tiles.xml under WEB-INF so URLs cannot fetch it directly.
Share this post:

Comments (0)

Please login or register to comment.

Create a free account to keep reading

You've enjoyed a free tutorial! Register (it's free) to unlock every tutorial, track your progress and save code.

or sign in with your account

Already have an account? Log in