svaj
svaj

Reputation: 157

Tiles - Spring MVC

What is the difference between

<tiles:useAttribute ...>

and

<tiles:insertAttribute ...>

Can you give some example?

Upvotes: 2

Views: 4619

Answers (2)

svaj
svaj

Reputation: 157

Thanks @JB Nizet!

Actually i needed this tile attribute to be used in jsp page. I have found the difference and its almost same thing that you explained. However, I would like to share my example to those who are trying it on jsp page

code snippet of myLayout.jsp

<tiles:useAttribute name="my_title"/>
<c:if test="${not empty my_title}">
    <tiles:insertAttribute name="my_title"/>
</c:if>

useAttribute will in some sense convert "my_title" into a variable which now can be manipulate as a normal jsp variable. This new variable will carry the value provided by tiles definition. Hence, the variable can be checked if its empty or blank and if it is not empty, the value is outputed to the browser(response) by using insertAttribute

Here is the sample tile definition:

<definition name="test" template="myLayout.jsp">    
    <put-attribute name="my_title" value="Web Blog" />
</definition>

enjoy!

Upvotes: 3

JB Nizet
JB Nizet

Reputation: 691625

See http://tiles.apache.org/2.2/framework/tiles-jsp/tlddoc/tiles/insertAttribute.html and http://tiles.apache.org/2.2/framework/tiles-jsp/tlddoc/tiles/useAttribute.html.

useAttribute declares a variable containing the attribute. insertAttribute inserts the attribute in the response. It's basically the same difference as there is between

String id = attributeValue("theAttribute");

and

out.println(attributeValue("theAttribute"));

Upvotes: 3

Related Questions