[opencms-dev] RE: RE: Need help with templates, please

Christoph Schönfeld cschoenfeld at sylphen.com
Wed Apr 18 13:40:44 CEST 2007


Jonathan, once again you have given the most relevant hint about a 
problem. Thank you very much for your answers on this list.

I had the same/similar problem. I needed to include rendered xmlcontent 
files from a central portal template.

Here is how I made sure that the JSP knows which resource it's supposed 
to render.

My central template receives the path of the xmlcontent file to include 
as a request parameter and uses <cms:include page="article.jsp"/> to 
include the file. article.jsp is also set as the template-elements 
property of the xmlcontent files. The path of the file is passed to 
article.jsp via the HTTP session.

My code in article.jsp determines the path from the session and then 
sets it as a page context variable which is referred to by the 
contentload tag. If no path is found in the session it is assumed that 
the xmlcontent file is called directly within the Explorer or by 
invocation of its URL. In this case the page context variable is set to 
the value of the OpenCms request context URI (which has the same value 
as ${opencms.uri}).

Code snippet from article.jsp:
<%
String path = // something like session.getAttribute("...");
if (null == path) {               
    CmsJspActionElement jsp =
      new CmsJspActionElement(pageContext, request, response);
    pageContext.setAttribute("uri", jsp.getRequestContext().getUri());
} else {
    pageContext.setAttribute("uri", path);
}
%>
<cms:contentload collector="singleFile" param="${pageContext.uri}"
    editable="true">
</cms:contentload>


Best regards,
Christoph



More information about the opencms-dev mailing list