4

I have one template JSP page:

<html>
<head></head>
<body>
    <c:set var="temp" scope="request" value="" />
    <tile:insertAttribute name="header"/>
    <tile:insertAttribute name="body"/>
    <tile:insertAttribute name="footer"/>
</body>
</html>

My template XML is below:

<tiles-definitions>

    <definition name="home" extends="template">
        <put-attribute name="temp" value="home" />
        <put-attribute name="body" value="/WEB-INF/pages/home.jsp" />  
    </definition>

    <definition name="template" template="/WEB-INF/templates/template.jsp">
        <put-attribute name="temp" />
        <put-attribute name="header" value="/WEB-INF/pages/includes/header.jsp" />
        <put-attribute name="body"  />
        <put-attribute name="footer" value="/WEB-INF/pages/includes/footer.jsp" />
    </definition>
<tiles-definitions>

My question:

When I have set "home" value in "temp" name in home definition, I want to get this "home" value in header page and footer page so I am do ${temp} but I haven't found "home" value.

It's possible? If yes then how?

Roman C
  • 49,761
  • 33
  • 66
  • 176
Akash Chavda
  • 1,185
  • 1
  • 11
  • 29

2 Answers2

5

You can use tiles to print attribute to JSP and set to the request scope variable or create a request scope variable with tile:useAttribute. For example in the first case you can do

<html>
<head></head>
<body>
    <c:set var="temp" scope="request"><tile:getAsString name="temp"/></c:set>
    <tile:insertAttribute name="header"/>
    <tile:insertAttribute name="body"/>
    <tile:insertAttribute name="footer"/>
</body>
</html>
Roman C
  • 49,761
  • 33
  • 66
  • 176
0

You are mixing up Jstl core tags in tiles tag.

Use

<tiles:getAsString name="temp" />

instead of

<c:set var="temp" scope="request" value="" />

Refer https://tiles.apache.org/framework/tutorial/basic/pages.html

Darshan Patel
  • 2,839
  • 2
  • 25
  • 38