You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tiles.apache.org by Ken Bowen <kb...@als.com> on 2010/03/18 17:41:57 UTC
Problem passing attribute from Definition to Layout
Hi All (esp. Antonio),
I'm having a problem passing an attribute from a Tiles definition into
a layout page.
This is something which works for me using Tiles 2.06 on Tomcat 6.0.20,
but is failing using Tiles 2.07 on Google App Engine.
Here is my stripped-down example. The target browser page will be
testa.jsp
The desired goal is to pass the "pagename" attribute from tiles-
defs.xml to testLayout.jsp:
{And the real goal is to get that parameter value passed into the
Javascript for the page.}
testa.jsp
=============
<%@ page contentType="text/html;charset=UTF-8" language="java"
session="false" %>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<tiles:insertDefinition name="test.testa" />
------------
testLayout.jsp
==============
<%@ page contentType="text/html;charset=UTF-8" language="java"
session="false" %>
<%@page import="java.net.URLDecoder"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<tiles:importAttribute name="pagename" /> <<<<<<<
Tiles import here
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd
">
<html>
<head>
<meta http-equiv="content-type" content="text/html;
charset=UTF-8">
<title><tiles:getAsString name="page_title"/></title>
</head>
<script type='text/javascript'>
function pageinit(whatpage){
alert("pageinit: "+whatpage);
}
</script>
</head>
<body onload="pageinit('${pagename}');">
<<<<<<<<<< Evaluate import here
<h1><tiles:getAsString name="page_title"/></h1>
layout stuff....
</body>
</html>
------------
tiles-defs.xml
=============
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>
<definition name="test.common" template="/layouts/testLayout.jsp">
<put-attribute name="footer" value="/tiles/myfooter.jsp" />
<put-attribute name="pagename" value="defaultpage" />
</definition>
<definition name="test.testa" extends="test.common">
<put-attribute name="pagename" value="test.atesta" />
<<<<< Attribute value originates here
<put-attribute name="page_title" value="Test TestA" />
</definition>
</tiles-definitions>
------------
I expect to see the Javascript alert showing:
pageinit: test.testa
However, I only get
pageinit: ${pagename}
The complete generated page source for testa.jsp is:
=============
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd
">
<html>
<head>
<meta http-equiv="content-type" content="text/html;
charset=UTF-8">
<title>Test TestA</title>
</head>
<script type='text/javascript'>
function pageinit(whatpage){
alert("pageinit: "+whatpage);
}
</script>
</head>
<body onload="pageinit('${pagename}');">
<h1>Test TestA</h1>
layout stuff....
</body>
</html>
------------
I have the standard.jar and jstl.jar jars on the classpath. I /
thought/ that and Tiles was all I used in the Tiles 2.06 + Tomcat
project where this works. I'm probably missing something, but I don't
see what.
Any pointers/thoughts on what I've missed will be greating appreciated.
Thanks in advance,
Ken Bowen
Re: Problem passing attribute from Definition to Layout
Posted by Ken Bowen <kb...@als.com>.
That may be the problem. I'm having difficulty in determining just
what Servlet/JSP is supported by Google App Engine.
Fortunately, I just realized there is a "workaround" for me that skips
the ImportAttribute and $() Namely, using the same Tiles Definitions
in my example, I just need to write
<body onload="pageinit('<tiles:getAsString name="pagename"/>');">
to get the desired value of "pagename" from the Definition passed into
Javascript for the testLayout.jsp page.
But I'll look into what Servlet/JSP is supported by Google App Engine,
or whether it will allow me to use custom tags.
Thanks much,
Ken
On Mar 18, 2010, at 12:48 PM, Antonio Petrelli wrote:
> 2010/3/18 Ken Bowen <kb...@als.com>:
>> I expect to see the Javascript alert showing:
>> pageinit: test.testa
>>
>> However, I only get
>> pageinit: ${pagename}
>
> What servlet version are you using? To use EL directly in JSP pages
> (without custom tags) you must use at least Servlet 2.4/JSP 2.0.
>
> Antonio
Re: Problem passing attribute from Definition to Layout
Posted by Antonio Petrelli <an...@gmail.com>.
2010/3/18 Ken Bowen <kb...@als.com>:
> I expect to see the Javascript alert showing:
> pageinit: test.testa
>
> However, I only get
> pageinit: ${pagename}
What servlet version are you using? To use EL directly in JSP pages
(without custom tags) you must use at least Servlet 2.4/JSP 2.0.
Antonio