You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tiles.apache.org by Steven Lee <st...@comcast.net> on 2008/10/25 12:15:21 UTC

How to make Java variables accessible across Tiles attribute

I am converting a web-based application to use Tiles.  The application 
has Java code embedded in the JSP pages.  The general template is 
something like the following which I've simplified:

<html>
<head>
<tiles:insertAttribute name="head" />
</head>
<body>
<tiles:insertAttribute name="content" />
</body>
</html>


Here is a sample JSP.

<tiles:insertTemplate template="/layouts/main.jsp" flush="true">
<tiles:putAttribute name="head" type="string">
<%
    String tmp = "JSP Test";
%>
</tiles:putAttribute>

<tiles:putAttribute name="content" type="string">
<p><%= tmp %></p>
</tiles:putAttribute>
</tiles:insertTemplate>


This won't compile because the Tile attribute 'content' doesn't have 
access to the 'tmp' variable defined in another Tiles attribute.  
Looking at the generated Java code, the output of each Tile attribute is 
within a do { } construct.  Is there a way to make all Java variables 
accessible within the JSP page as I had before using Tiles?

-Steven


Re: How to make Java variables accessible across Tiles attribute

Posted by Antonio <an...@gmail.com>.
2008/10/25 Steven Lee <st...@comcast.net>:
> <tiles:putAttribute name="head" type="string">
> <%
>   String tmp = "JSP Test";
> %>
> </tiles:putAttribute>
>
> <tiles:putAttribute name="content" type="string">
> <p><%= tmp %></p>
> </tiles:putAttribute>

The "tmp" variable is visible only inside the first
<tiles:putAttribute> tag. This is a JSP specification. Simply specify
the "tmp" variable in a place that is visible to both tags.

Antonio

Re: How to make Java variables accessible across Tiles attribute

Posted by Ken Bowen <kb...@als.com>.
This looks like it would better to ask on the Tiles mailing list:  http://tiles.apache.org/mail.html 
  (bottom of page to subscribe).

On Oct 25, 2008, at 6:15 AM, Steven Lee wrote:

> I am converting a web-based application to use Tiles.  The  
> application has Java code embedded in the JSP pages.  The general  
> template is something like the following which I've simplified:
>
> <html>
> <head>
> <tiles:insertAttribute name="head" />
> </head>
> <body>
> <tiles:insertAttribute name="content" />
> </body>
> </html>
>
>
> Here is a sample JSP.
>
> <tiles:insertTemplate template="/layouts/main.jsp" flush="true">
> <tiles:putAttribute name="head" type="string">
> <%
>   String tmp = "JSP Test";
> %>
> </tiles:putAttribute>
>
> <tiles:putAttribute name="content" type="string">
> <p><%= tmp %></p>
> </tiles:putAttribute>
> </tiles:insertTemplate>
>
>
> This won't compile because the Tile attribute 'content' doesn't have  
> access to the 'tmp' variable defined in another Tiles attribute.   
> Looking at the generated Java code, the output of each Tile  
> attribute is within a do { } construct.  Is there a way to make all  
> Java variables accessible within the JSP page as I had before using  
> Tiles?
>
> -Steven
>