Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session
SOLVED

Nesting in jsp includes unexpected tags

Avatar

Former Community Member

I have two components, C1 and C2.  C2 can contain C1 components.

C1 has a jsp file called "c1.directive.jsp" which outputs some xml-like data:

<c1-element></c1-element>

C2 has a jsp file called "c2.directive.jsp" which outputs some xml-like data and also tries to output the directive.jsp of its C1 children:

<c2-element> // for each child, get childpath and append "directive" selector <sling:include path="<%=childpath%>" </c2-element>

When I request "[server]/content/.../c1.directive", I get the result I expect:

<c1-element></c1-element>

However, when I request "[server]/content/.../c2.directive", I get this:

<c2-element> <div class="parbase c1"> <c1-element></c1-element> <script type="text/javascript"> CQ.WCM.edit({"path":"/content/.../c1","dialog":"/apps/.../c1/dialog","type":"../c1","csp":"c1|page/menu|parbase/c1|parbase"}); </script> </div> </c2-element>

Why do I get the correct response when I request the C1 directive directly, but not when the same path is sling:include'd in another jsp?  Why do I get the <div> and <script> tags and how can I prevent this?

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

So in the end, this is what I did and it worked for me:

(1) I changed my request to be: [server]/content/.../c2.directive?wcmmode=disabled

That removed the <script> tags. 

(2) Then, to remove the CQ decoration tags, I created a jsp containing the following:

if (WCMMode.fromRequest(request) != WCMMode.EDIT && WCMMode.fromRequest(request) != WCMMode.DESIGN) { IncludeOptions.getOptions(request, true).forceSameContext(Boolean.TRUE).setDecorationTagName(""); }

and included that jsp in my directive.jsps.

View solution in original post

4 Replies

Avatar

Level 10

This question comes up from time to time. When nesting components in CQ - there are some restrictions around listeners, etc. See this doc topic:

http://docs.adobe.com/docs/en/cq/5-6-1/developing/components.html

Avatar

Level 10

Hi,

    You are getting a correct response. Take a printout+ attach to desk or Keep [1] handy it will solve many issue.

  • sling:include Includes a resource rendering into the current page
  • When invoking c2 The path passed to sling:include is "/content/.../c1"  hence c1 script is invoked and it is as designed.
    • If your use case is to skip child nodes of c1 make sure to implement filter or logic accordingly
  • Out of the box author is for editing and publish for read only.  For authors to edit the content aem automatically injust the div and script so that you can do edit & as well as in line editing. That is why you are seeing <div> and <script>
    • You can test with adding a editmode as disabled or preview & you wont see the rendering script part  Ex:-  [server]/content/.../c2.directive?wcmmode=disabled
  • I would suggest to attend [2] & things should get cleared.

[1]   http://dev.day.com/content/ddc/blog/2008/07/cheatsheet/_jcr_content/images/cheatsheet/front.png

[2]   http://training.adobe.com/training/courses/cq5-developer-training.html

Thanks,

Sham

Avatar

Former Community Member

I think you misunderstood me.  The output of my component.directive.jsps have nothing to do with widgets or component development per se.  

At it's very basic, my question is: (1) why does sling resolve my .directive selector differently when the path is included in another jsp versus when I request the same path directly? and (2) how can I fix this?

Avatar

Correct answer by
Former Community Member

So in the end, this is what I did and it worked for me:

(1) I changed my request to be: [server]/content/.../c2.directive?wcmmode=disabled

That removed the <script> tags. 

(2) Then, to remove the CQ decoration tags, I created a jsp containing the following:

if (WCMMode.fromRequest(request) != WCMMode.EDIT && WCMMode.fromRequest(request) != WCMMode.DESIGN) { IncludeOptions.getOptions(request, true).forceSameContext(Boolean.TRUE).setDecorationTagName(""); }

and included that jsp in my directive.jsps.

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----