Neha Chhatwani
Neha Chhatwani

Reputation: 11

Not able to retrieve the output on jsp page using tiles framework

I have created a project using struts2 and spring frameworks. Now I am trying to separate my dynamic content using tiles framework. The layout consists of a header and body. The header in turn contains Welcome xyz (name of the logged user) and body part contains a tabular listing of people, populated from my database on startup.

Following is my Tiles layout code

Layout.jsp

<body>
<tiles:insertAttribute name="header"/>
<tiles:insertAttribute  name="body"/>
</body>

tiles.xml

<tiles-definitions>
    <definition name="baseLayout" template="layout.jsp">
        <put-attribute name="header" value="welcome.jsp"/>
        <put-attribute name="body" value=""/>
    </definition>
    <definition name="addToListLayout" extends="baseLayout">
        <put-attribute name="body" value="addEmployee.jsp"/>
    </definition>
</tiles-definitions>

But after the login Iam getting the following output on jsp :-


welcome.jsp addEmployee.jsp


Can any one let me know why I am getting the names of jsp rather than the content?

Upvotes: 1

Views: 785

Answers (1)

Greg Leaver
Greg Leaver

Reputation: 801

The issue is that tiles is not interpreting your attributes as templates, it is interpreting them as strings. From the tiles doc:

This tag can be flexibly used to insert the value of an attribute into a page. As in other usages in Tiles, every attribute can be determined to have a "type", either set explicitly when it was defined, or "computed". If the type is not explicit, then if the attribute value is a valid definition, it will be inserted as such. Otherwise, if it begins with a "/" character, it will be treated as a "template". Finally, if it has not otherwise been assigned a type, it will be treated as a String and included without any special handling.

So you can change your tag in tiles.xml to either this:

<put-attribute name="header" value="/welcome.jsp"/>

or this:

<put-attribute name="header" type="template" value="welcome.jsp"/>

Upvotes: 1

Related Questions