You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tiles.apache.org by duvduv <du...@gmail.com> on 2011/07/09 10:34:46 UTC

Partial include with Tiles

Hey all,

I'm new to Tiles and I'm having a bit of a difficulty maintaining a
large set of views. Maybe someone can tell me what I'm doing wrong/how
can I do it better.

I'm developing a webapp with many views, all of these are composed
around a single template. The template has about three or four
"placeholders" (attributes), and for each view, different, dynamically
generated content (JSP for that matter) should be placed in the
correct placeholder.

When I define a new view with Tiles I need to create multiple JSP file
- each with a placeholder's content. Then I need to update a huge XML
definition file that has a lot of entries that look just the same, and
a similar properties file (I'm working with Spring's
ResourceBundleViewResolver but that's not the main issue).

I'm looking for a solution that'll allow me to declare all these
placeholder's content in the same file, and partially include this
file into the template (every fragment to its placeholder).

For example, I might be having this as template.jsp:

    [...]
    <html>
    <head> [...] </head>
    <body>
    <div class="head">
        <tiles:insertAttribute name="head" />
    </div>
    <div class="body">
        <tiles:insertAttribute name="body" />
    </div>

Then I'll define the following tiles:

    <definition name="template" template="/WEB-INF/views/template.jsp" />
    <definition name="someView" extends="template">
        [something that points Tiles to someView.jsp - maybe it can
infer the file's name from the definition's name]
    </definition>

Then having someView.jsp as follows:

    <tiles:putAttribute name="head">
        <!-- This will be evaluated as JSP content -->
        <h1>Here's the title</h1>
    </tiles:putAttribute>
    <tiles:putAttribute name="body">
        <p>And here's the body...</p>
    </tiles:putAttribute>

Instead of having someView_head.jsp and someView_body.jsp each with a
single line.

Am I doing it all wrong? Is there another way I'm not aware of?

Thanks!

- Itay

Re: Partial include with Tiles

Posted by Antonio Petrelli <an...@gmail.com>.
2011/7/9 duvduv <du...@gmail.com>

>    <tiles:putAttribute name="head">
>        <!-- This will be evaluated as JSP content -->
>        <h1>Here's the title</h1>
>    </tiles:putAttribute>
>    <tiles:putAttribute name="body">
>        <p>And here's the body...</p>
>    </tiles:putAttribute>
>

It should work if you escape the text, or wrap it around a <![[CDATA]]>.
Notice that only static text can be placed this way.

Antonio