• Post Reply Bookmark Topic Watch Topic
  • New Topic

Tiles Context is there and is not there?  RSS feed

Milan Tomc
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone.
I have a really strange problem and I guess I went blind and simply can't see what is going on.
I'm using tiles (for the first time) and getting the 2 errors below.

First I've got this one:
Error - tag.getAsString : component context is not defined. Check tag syntax

then I added SCRIPTING FOR TESTING to see what is going on and this is what I get

***Title is: Categories
***header is: /jsp/Header.jsp
***Crumbs is: /jsp/Crumbs.jsp
***Category is: /jsp/Category.jsp

Now, as you can see below, these results come from the very Context "which is not defined" ???

then I removed <tiles:getAsString name="title"/> and inserted just 'MyTitle' (hardcoded title that is)
and got this error (the if part of SCRIPTING FOR TESTING):


Can not find Tile context for 'org.apache.jsp.CategoryLayout_jsp'. TilesAction subclasses must be called from a Tile
at org.apache.jsp.CategoryLayout_jsp._jspService(CategoryLayout_jsp.java:117)

and this in the page (the else part of SCRIPTING FOR TESTING):

***Title is: My app title - categories
***header is: /jsp/Header.jsp
***Crumbs is: /jsp/Crumbs.jsp
***Category is: /jsp/Category.jsp

also from the "unexisting" context.

Below the jsp and the tiles-def.xml

THE CategoryLayout.jsp:
<%@ page language="java" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:base />

<tiles:getAsString name="title"/> [later replaced by just 'MyTitle']




org.apache.struts.tiles.ComponentContext context = org.apache.struts.tiles.ComponentContext.getContext(request);

if (context == null) {

throw new ServletException("Can not find Tile context for '"

+ this.getClass().getName()

+ "'. TilesAction subclasses must be called from a Tile");

} else {

out.print("<br />");
out.print("***Title is: " + (String) context.getAttribute("title"));
out.print("<br />");
out.print("***header is: " + (String) context.getAttribute("header"));
out.print("<br />");
out.print("***Crumbs is: " + (String) context.getAttribute("crumbs"));
out.print("<br />");
out.print("***Category is: " + (String) context.getAttribute("body"));

<tiles:insert attribute="header" />

<TR vAlign=top>

<tiles:insert attribute="leftmenu" />
<tiles:insert attribute="crumbs" />
<tiles:insert attribute="body" />


<!-- Base Tiles Definition -->
<definition name="base.definition" path="/siteLayout.jsp">
<put name="title" value="My app title"/>
<put name="header" value="/jsp/Header.jsp" />
<put name="leftmenu" value="/jsp/LeftMenu.jsp" />
<!-- Tiles Definition of welcome page -->
<definition name="page.welcome" extends="base.definition">
<put name="body" value="/jsp/welcome.jsp" />
<!-- Tiles Definition of Categories -->

<definition name="page.categories" extends="base.definition" path="/CategoryLayout.jsp">
<put name="title" value="My app title - categories"/>
<put name="crumbs" value="/jsp/Crumbs.jsp" />
<put name="body" value="/jsp/Category.jsp" />

<definition name="navigation.definition" path="/jsp/Navigate.jsp" />



The page is displayed correctly and everything works just fine, except for this exception stack on the sysout.

Any ideas?

ps. if you look carefully in the SCRIPTING FOR TESTING part you'll see that there is an if-else construction, but they seem both to be executed???

Milan.javascript: x()
[ March 19, 2007: Message edited by: Milan Tomc ]
Milan Tomc
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my Action class (within method getMainCategories() ) :

I have got this

What am I missing here?

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!