0

I'm using Tiles 2.2 and I'd like to reuse a single JSP to display different messages. Messages have to be defined inside Tiles configuration file.

The following example is my approach: base is the base abstract definition all other definitions extend, while display would be an another abstract definition, used as a template for displaying messages. page1 and page2 are two final pages examples, each one displays a different message.

<definition name="base" template="layout.jspx"/>

<definition name="display" extends="base">
        <put-attribute name="body" value="display.jspx"/>
</definition>

<definition name="page1" extends="display">
        <put-attribute name="message" value="This is one message!"/>
</definition>

<definition name="page2" extends="display">
        <put-attribute name="message" value="This is another message!"/>
</definition>

display.jspx would have something like this inside:

<tiles:useAttribute name="message"/>
Message: ${message}

But I couldn't make it to work, because when opening page1 or page2 I get an exception saying message attribute is null.

Is there an easy way to set up something like this, without modifying base template and definition?

Thanks in advance

user683887
  • 1,260
  • 1
  • 10
  • 20
  • It's been a while since I've used Tiles. I think I remember having to put type="string" on attributes of type string. – JB Nizet Nov 29 '11 at 22:12

1 Answers1

1

Probably too late, but I believe you need to add cascade="true" to your put-attribute elements for name="message".

Chris Goldman
  • 307
  • 1
  • 10