[opencms-dev] using cms:include from a jsp

Florian Hopf hopf at synyx.de
Fri Dec 31 16:45:17 CET 2010


Hi Mario,

I think the problem can be seen nicely if you have a look at boxes.jsp
in templatetwo:

<c:set var="type"
value="${cms:vfs(pageContext).readResource[element.value['File']].typeId}"/>
  <c:choose>
    <%-- Text Boxes --%>
    <c:when test="${type == 72}">
      <cms:include
file="%(link.weak:/system/modules/org.opencms.frontend.templatetwo/elements/boxes/textbox.jsp:52db3537-d890-11dc-8ec1-3bdd2ea0b1ac)">
        <cms:param name="file" value="${element.value['File']}" />
	<cms:param name="schema" value="${element.value['ColorSchema']}"/>
      </cms:include>
    </c:when>
    ...

You need to check the type of the content to include for determining
which jsp to use. Also, you need to pass the path of the content to
render to the JSP as a param, which needs special treatment in the JSP
that is included. This leads to two problems: You need to adjust the
including file (in this case boxes.jsp) for every new element that you
want to include. Also you probably need to maintain two jsps for
rendering the file: One for being included from JSPs (using the
parameter in contentload) and one for rendering the content directly.

It would be really nice to have something that lets you just include xml
content and automatically determines the JSP to use (and of course
automatically adjusts the context information like opencms.uri).

BTW: When replying Thunderbird cuts off the content after the signature
marker. As your signature is in the middle of the mails the rest of the
mail is lost. It might be better if you place your signature at the end
of the mail.

Regards
Florian

Mario Jäger schrieb:
> Hi,
> 
> When an user requests the URI of a xml content resource in OpenCms, then 
> the "template-elements" property is read from the requested resource. If 
> it contains a path to a JSP, this JSP is called. The JSP reads the XML 
> content from the requested resource and renders it’s output from it. 
> This is not the behaviour for a xml content you include in a jsp with 
> <cms:include>. For example, the "template-elements" property of the xml 
> content is not used then. <cms:include> dynamically includes JSP 
> elements. Usually, <cms:include> is used with a "file" (or "property") 
> attribute to specify the resource providing the included jsp element: 
> <cms:include file="..." element="..." />. The "Null Pointer Exception" 
> (you wrote in your first mail of) you get, because you used the 
> <cms:include> for the xml content without the "element" attribute (you 
> should use the <cms:content...> tags, not the <cms:include> tag to 
> access the XML content elements). It seems, that the xml content we 
> speak of, only shall be a sub element in the page you want to render. 
> Only, if I would know the content of your module and some more details 
> to the target you want to reach, I could say, if it could be improved. 
> But, you say, that generally it works...
> 




More information about the opencms-dev mailing list