[opencms-dev] Trouble with <c:set> and <cms:include>

Claus Priisholm cpr at codedroids.com
Sun Jul 16 11:41:06 CEST 2006


I'm trying to boil down a problem I have with a custom tag I'm doing.
Basically I am trying to catch the processed output (i.e. the tag has 
<bodycontent>JSP</bodycontent> set in the TLD) from <cms:include>.

It turns out that JSTL has the same problem, so I'll use the <c:set>  as 
an example:

<%@ page session="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %>
<html>
   <head>
     <title>Test</title>
   </head>
   <body>
     <%-- A --%>
     <c:set var="jspvar"><jsp:include page="test.jsp" /></c:set>
     <hr>
     <%= "A[ "+pageContext.getAttribute("jspvar")+" ]" %>
     <hr>
     <%-- B --%>
     <c:set var="cmsvar"><cms:include page="test" /></c:set>
     <hr>
     <%= "B[ "+pageContext.getAttribute("cmsvar")+" ]" %>
     <hr>

   </body>
</html>

The test.jsp simply prints out the system time in milliseconds.

When invoking this JSP from within the workplace the output is an empty 
page (no tags or anything). If the <c:set></c:set> tag is removed from 
the B-part, then the output is shown (though there of couse is no 
"cmsvar" attribute so it prints null).

When including the A and B parts into a template (e.g. the welcome 
template), then the behaviour is different (but still unexpected), when 
viewing a page that uses that template. Here the output related to the 
test is like:

---------------------------
A[ 1153042041016 ]
---------------------------
---------------------------
B[ ]
---------------------------
1153042041022

I.e. in the B-part nothing gets stored by the <c:set>-tag, but 
subsequently (outside of the enclosing pair of <hr>'s) the output of the 
included JSP pops up...

I suspect it has to do with which JspWriter actually gets written to, 
but looking at the source for the include tag does not reveal any 
'deviant' behaviour - it writes to pageContext.getOut() which by means 
of the BodyTagSupport class should be set to the BodyContent writer 
provided by the <c:set>-tag. But it does not seem to be the case.

Has anyone found a way around this?

Test environment was 6.2.1, Tomcat 5.5, Java 1.5



More information about the opencms-dev mailing list