[opencms-dev] Apply template on nested xmlcontent

Stephan Hartmann hartmann at metamesh.de
Fri Mar 7 10:40:55 CET 2014


Hi Thomas,

You cannot pass objects as request parameters (that's what cms:param tag
does).
Instead you could either store your object in request scope and then access
it in your included JSP.

Including JSP:

<cms:contentloop element=*"options"*>

       <cms:contentaccess var=*'optionContent'* scope="request" />

                <cms:include file=
*"/system/modules/cn.bmw.opencms.mysql.ecrm/templates/option.jsp"*/>
</cms:contentloop>

Included JSP (no contentload needed!):

<c:if test="${optionContent.hasValue['value']">
  ${optionContent.value.value}
...
</c:if>
<c:if test="${optionContent.hasValue['text']">
  ${optionContent.value.text}
...
</c:if>

or you could pass your string values as request parameters:
<cms:include ...>
  <cms:param name="optionValue" value="${optionContent.value.value}"/>
  <cms:param name="optionText" value="${optionContent.value.text}"/>

</cms:include>

and access them as follows:
${param.optionValue}
${param.optionText}

HTH,
Stephan


2014-03-07 1:49 GMT+01:00 Thomas Adams <thomas.adams at interone.cn>:

>  Dear all,
>
>
>
> I try to apply a JSP template to nested content.
>
> I have a XSD  like :
>
>
>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified">
>
>        <xsd:include schemaLocation="opencms://opencms-xmlcontent.xsd"/>
>
>        <xsd:include schemaLocation="
> opencms://system/modules/cn.opencms.mysql.ecrm/schemas/formfields/option.xsd
> "/>
>
>        <xsd:element name="Selects" type="OpenCmsSelects"/>
>
>        …….
>
> <xsd:complexType name="OpenCmsSelect">
>
>               <xsd:sequence>
>
>                      <xsd:element name="options" type="OpenCmsOption"
> minOccurs="0" maxOccurs="unbounded"/>
>
>               </xsd:sequence>
>
>               <xsd:attribute name="language" type="OpenCmsLocale" use="
> optional"/>
>
>        </xsd:complexType>
>
> </xsd:schema>
>
>
>
> With the CmsOption XSD:
>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified">
>
>
>
>        <xsd:include schemaLocation="opencms://opencms-xmlcontent.xsd"/>
>
>
>
>        <xsd:element name="Options" type="OpenCmsOptions"/>
>
>        ….
>
>        <xsd:complexType name="OpenCmsOption">
>
>               <xsd:sequence>
>
>                      <xsd:element name="value" type="OpenCmsString"
> minOccurs="1" maxOccurs="1"/>
>
>                      <xsd:element name="text" type="OpenCmsString"
> minOccurs="1" maxOccurs="1"/>
>
>               </xsd:sequence>
>
>               <xsd:attribute name="language" type="OpenCmsLocale" use="
> optional"/>
>
>        </xsd:complexType>
>
> </xsd:schema>
>
>
>
> And the option template option.jsp as :
>
> <cms:contentload collector=*'singleFile'* param=*'%(opencms.filename)'*>
>
> <cms:contentaccess var=*'optionContent'* />
>
>        <cms:template element=*"option"*>
>
>               <c:set var=*'optionValue'* value=*''*/>
>
>               <cms:contentcheck ifexists=*'optionContent.value'*>
>
>                      <c:set var=*'optionValue'*><cms:contentshow element=
> *'optionContent.value'* /></c:set>
>
>               </cms:contentcheck>
>
>               <c:if test=*'*${!*empty *optionValue}*'*>
>
>                      <c:set var=*'optionValue'* value=*' value="*${value}
> *"'*/>
>
>               </c:if>
>
>
>
> <c:set var=*'optionText'* value=*''*/>
>
>               <cms:contentcheck ifexists=*'optionContent.text'*>
>
>                      <c:set var=*'optionText'*><cms:contentshow element=
> *'optionContent.text'* /></c:set>
>
>               </cms:contentcheck>
>
>               <option<c:out escapeXml=*'false'* value='
> ${optionClass}${optionId}${optionDisabled}${optionSelected}${optionValue}'
> />><c:out value=*"*${optionText}*"*/></option>
>
>        </cms:template>
>
> </cms:contentload>
>
>
>
> For both XSD I have setup corresponding resourcetypes and corresponding
> templates JSP’s
>
> Within the template for the select now I want to apply the template of the
> options resource like:
>
>
>
> <cms:contentloop element=*"options"*>
>
>        <cms:contentaccess var=*'optionContent'* />
>
>                 <cms:include file=
> *"/system/modules/cn.bmw.opencms.mysql.ecrm/templates/option.jsp"*>
>
>               <cms:param name=*"optionContent"* value=*"*${optionContent}
> *"*/>
>
>        </cms:include>
>
> </cms:contentloop>
>
>
>
> But in the end the options get not correctly rendered the [text] and
> [value] are missing:
>
> It renders something like:
>
> <select …..>
>
>                 <option></option>
>
>                 <option></option>
>
>                 <option></option>
>
> <select>
>
>
>
> With empty options, Is there any way to achieve this  and to avoid to
> repeat
>
> Template code from the option template in the select template again?
>
>
>
>
>
> *Thomas Adams**德勤*
> DIRECTOR APPLICATION DEVELOPMENT
>
>
> [image: io]
>
>
> *INTERONE CHINA // AN AGENCY OF BBDO WORLDWIDE 1604, E -TOWER, 12 GUANGHUA
> ROAD, CHAOYANG DISTRICT, BEIJING 100020, CHINA*
> 北京天一国际广告有限公司
> 光华路丙12号数码01大厦1604室,100020 北京,朝阳区
>
> *PHONE* +86 10.65 91 3792 *EXT.* -3026 *// MOBILE* +86 139 1059 0750
>
> *WWW.INTERONE.CN*<https://mail.weboutlook.hk/owa/redir.aspx?C=4f9ed844d60c4108874abc272e3662e9&URL=http%3a%2f%2fwww.interone.cn%2f>
>
> PLEASE CONSIDER THE ENVIRONMENT BEFORE PRINTING THIS E-MAIL.
>
>
>
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20140307/ec732b4c/attachment.htm>


More information about the opencms-dev mailing list