Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

how to add jsp variable to cq:inlcude path

Avatar

Level 2

Hi

I have  a component which use to display all the node detail in a specific folder.  But there is some problem when a pass a <%=variable%> to cq:include.  When I read the source using firefox.  It seems it can not read the jsp variable  correctly.  Please help.

Below is the source from firefox when I open the page.   cqinclude seems cannot understand <%=noticeName%> is a jsp variable.  It just print it out as it is.

<li id="notice-board-item-12" class="alphabet-a"><div class="parbase notice">
<h1><div><span class="cq-text-placeholder-ipe">&para;</span></div></h1><h2><div><span class="cq-text-placeholder-ipe">&para;</span></div></h2><img src="/libs/cq/linkchecker/resources/linkcheck_o.gif" alt="invalid link: &lt;div&gt;&lt;span class=" title="invalid link: &lt;div&gt;&lt;span class=" border="0">More<img src="/libs/cq/linkchecker/resources/linkcheck_c.gif" border="0">
<script type="text/javascript">
CQ.WCM.edit({"path":"/content/bochk_web/zh_hk/noticeboard/<%=noticeName%>/jcr:content/notice","dialog":"/apps/bochk_web/components/notice/dialog","type":"bochk_web/components/notice","csp":"page_noticeboard|page/noticeboard/notice|parbase","editConfig":{"inplaceEditingConfig":{"active":true,"editorType":"text","configPath":"/apps/bochk_web/components/notice/cq:editConfig/cq:inplaceEditing/../../dialog/items/tab1/items/text"}}});
</script>
</div>
</li> 

Below is the source code of the component:

while (noticeBoardChildNodes.hasNext()){ Node notice = (Node) noticeBoardChildNodes.next(); if (notice.hasProperty("jcr:primaryType")){ if (notice.getProperty("jcr:primaryType").getString().equals("cq:Page")){ String noticeName = notice.getName(); %> <li id="notice-board-item-<%=count%>" class="alphabet-a"><cq:include path="../../<%=noticeName%>/jcr:content/notice" resourceType="bochk_web/components/notice" /></li> <% count ++; } } }
1 Accepted Solution

Avatar

Correct answer by
Employee

Hi,

In

<cq:include path="../../<%=noticeName%>/jcr:content/notice" resourceType="bochk_web/components/notice" />

../../<%=noticeName%>/jcr:content/notice is not a valid expression. If you use a Java expression in a JSP attribute, it must be the entire attribute, so what you would have to do is specify path as <%= "../../" + noticeName + "/jcr:content/notice" %>. This is just how JSPs work.

The other alternative is to use EL expressions which are not subject to this same restriction and can go anywhere in the attribute value.

Regards,

Justin

View solution in original post

2 Replies

Avatar

Level 7

Hi,
it might be that the <cq:> taglib wont accept jsp variable in that way.
Can you try the following and see if that helps:
 

<% pageContext.setAttribute("noticeName", noticeName); %> //... <cq:include path="../../${noticeName}/jcr:content/notice" resourceType="bochk_web/components/notice" /> //...

Good luck,
Johan

Avatar

Correct answer by
Employee

Hi,

In

<cq:include path="../../<%=noticeName%>/jcr:content/notice" resourceType="bochk_web/components/notice" />

../../<%=noticeName%>/jcr:content/notice is not a valid expression. If you use a Java expression in a JSP attribute, it must be the entire attribute, so what you would have to do is specify path as <%= "../../" + noticeName + "/jcr:content/notice" %>. This is just how JSPs work.

The other alternative is to use EL expressions which are not subject to this same restriction and can go anywhere in the attribute value.

Regards,

Justin