aspose file tools*
The moose likes Struts and the fly likes Tiles Context is there and is not there? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Tiles Context is there and is not there?" Watch "Tiles Context is there and is not there?" New topic
Author

Tiles Context is there and is not there?

Milan Tomc
Greenhorn

Joined: Mar 06, 2006
Posts: 17
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):


javax.servlet.jsp.JspException

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:html>
<head>
<html:base />

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

</head>

<BODY>

<%//SCRIPTING FOR TESTING


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" />

<TABLE>
<TBODY>
<TR vAlign=top>

<TD>
<tiles:insert attribute="leftmenu" />
</TD>
<TD></TD>
<TD>
<tiles:insert attribute="crumbs" />
<tiles:insert attribute="body" />
</TD>
<TD</TD>
</TR>
</TBODY>
</TABLE>
</BODY>
</html:html>


----------------------------

<tiles-definitions>
<!-- 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" />
</definition>
<!-- Tiles Definition of welcome page -->
<definition name="page.welcome" extends="base.definition">
<put name="body" value="/jsp/welcome.jsp" />
</definition>
<!-- 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>

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


</tiles-definitions>


------------------------------

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???

Greatings,
Milan.javascript: x()
[ March 19, 2007: Message edited by: Milan Tomc ]
Milan Tomc
Greenhorn

Joined: Mar 06, 2006
Posts: 17
In my Action class (within method getMainCategories() ) :


I have got this



What am I missing here?

thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tiles Context is there and is not there?