You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tiles.apache.org by hannehomuth <ha...@gmx.de> on 2008/08/11 17:58:26 UTC
How to integrate Servlet generates pages in Tiles 2
Hello List,
I started developing with Apache Tiles 2 yesterday and I have a question
now. I generated me some tiles (footer, header, common_menu,etc). So now I
want to insert some pages, which's content is generated by a servlet. The
content is different by the given context. For now my jsp's look like this.
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<html>
<head>
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
<link href="css/layout.css" type="text/css" rel="stylesheet">
<title>AIS DCL</title>
</head>
<body>
<tiles:insertDefinition name="aisdcl.main" />
</body>
</html>
The definition in the tiles-defs.xml look like this
<definition name="aisdcl.main" template="layouts/layout.jsp">
<put-attribute name="title" value="This is the title2."/>
<put-attribute name="header" value="/tiles/banner.jsp"/>
<put-attribute name="body" value="/tiles/home_body.jsp"/>
<put-attribute name="common_menu" value="/tiles/common_menu.jsp"/>
<put-attribute name="contextMenu"
value="/tiles/contextMenuBlank.jsp"/>
<put-attribute name="footer" value="/tiles/credits.jsp"/>
</definition>
and the layout.jsp looks like this.
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<div class="header"><tiles:insertAttribute name="header"/></div>
<div id="rahmen">
<div id="menu"><tiles:insertAttribute name = "common_menu"/></div>
<div id="menu"><tiles:insertAttribute name = "contextMenu"/></div>
</div>
<div id="content" align="center"><tiles:insertAttribute name="body"/></div>
<div id="footer"><tiles:insertAttribute name="footer"/></div>
And it works quiet well. But now I want to insert some ServerSide generated
pages. I thought I could use a tile as single, you now this way:
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<html>
<head>
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
<link href="css/layout.css" type="text/css" rel="stylesheet">
<title>AIS DCL</title>
</head>
<body>
<tiles: PUT HEADER TILE HERE />
<tiles: MENU HERE TILE HERE />
THE CALL TO THE SERVELET GOES HERE
<tiles: PUT FOOTER TILE HERE />
</body>
</html>
But that seems not to work. I've tried it with
<tiles:insertAttribute name = "common_menu"/>
<html>
<head>
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
<link href="css/layout.css" type="text/css" rel="stylesheet">
<title>AIS DCL</title>
</head>
<body>
<tiles:insertAttribute name = "header"/>
<tiles:insertAttribute name = "common_menu"/>
THE CALL TO THE SERVELET GOES HERE
<tiles:insertAttribute name = "footer"/>
</body>
</html>
But it did'nt work.
Does anyone can give me an good example how to insert some NON TILES (in my
case only one) between some TILES ????
Thx for suggestions
--
View this message in context: http://www.nabble.com/How-to-integrate-Servlet-generates-pages-in-Tiles-2-tp18928638p18928638.html
Sent from the tiles dev mailing list archive at Nabble.com.
Re: How to integrate Servlet generates pages in Tiles 2
Posted by Greg Reddin <gr...@gmail.com>.
On Thu, Aug 14, 2008 at 9:52 AM, hannehomuth <ha...@gmx.de> wrote:
>
> <tiles:insertDefinition name = "example.header_menu_etc"/>
> <div id="mainContent">
> <%-- BECAUSE IM WRITTING JSP I COULD WRITE CODE LIKE IN SERVLETS HERE--&>
> <% String foo = request.getParameter("param1");%>
Yep, this is pretty much what the view preparer mechanism is designed
for. I would encourage you to look into that.
Greg
Re: How to integrate Servlet generates pages in Tiles 2
Posted by hannehomuth <ha...@gmx.de>.
Thx for your answer Greg,
i will look at that what you wrote. For now I went another way. I've build
two definitions. One for the Header and the Menu, and one for the footer.
And beetween them I wrote the code that is not always the same.
Example
<html>
<head>
<title>Example</title>
</head>
<tiles:insertDefinition name = "example.header_menu_etc"/>
<div id="mainContent">
<%-- BECAUSE IM WRITTING JSP I COULD WRITE CODE LIKE IN SERVLETS HERE--&>
<% String foo = request.getParameter("param1");%>
...
....
....
</div>
<tiles:insertDefinition name = "example.footer"/>
</html>
Thx for your reply
--
View this message in context: http://www.nabble.com/How-to-integrate-Servlet-generates-pages-in-Tiles-2-tp18928638p18983163.html
Sent from the tiles dev mailing list archive at Nabble.com.
Re: How to integrate Servlet generates pages in Tiles 2
Posted by Greg Reddin <gr...@gmail.com>.
On Mon, Aug 11, 2008 at 10:58 AM, hannehomuth <ha...@gmx.de> wrote:
>
>
> And it works quiet well. But now I want to insert some ServerSide generated
> pages. I thought I could use a tile as single, you now this way:
>
[snip]
> <tiles:insertAttribute name = "common_menu"/>
> THE CALL TO THE SERVELET GOES HERE
> <tiles:insertAttribute name = "footer"/>
It sounds like you might need to think about using a View Preparer
rather than a servlet. See here in the tutorial:
http://tiles.apache.org/tutorial/advanced/preparer.html
and here in the Javadoc:
http://tiles.apache.org/2.0/framework/apidocs/org/apache/tiles/preparer/ViewPreparer.html
and...
http://tiles.apache.org/2.0/framework/apidocs/org/apache/tiles/preparer/ViewPreparerSupport.html
>
> Does anyone can give me an good example how to insert some NON TILES (in my
> case only one) between some TILES ????
To my knowledge there's not a good way to "call" a servlet from a
tile. I'm sure it could be done, but I can't think of a *good* way :-)
If you can move the servlet code into a view preparer I think you will
be happier with the result.
HTH,
Greg