How to include an existing component multiple times

1.1k views Asked by At

I am going to create a component which needs to reuse the existing component 3 times. In my component's JSP file I added following but getting blank page when creating a template for my component and then creating a page for that template.

<%@taglib prefix="cq" uri="http://www.day.com/taglibs/cq/1.0" %><%
%>
haha
<cq:include path="test" resourceType="/apps/help/components/relatedlinks" />
<cq:include path="test1" resourceType="/apps/help/components/relatedlinks" />
<cq:include path="test2" resourceType="/apps/help/components/relatedlinks" />
1

There are 1 answers

0
Shawn On BEST ANSWER

Does it work when you only add 1 component and then break the moment you add a second component reference? If so, that is a good indication that there is something in your component code that is not self-contained. For example, maybe the component adds an attribute to the Request context instead of just the JSP context, causing the second instance to throw an exception. The error log will be your friend in this case--it should pinpoint what the exception is. Things to check for include:

  • Variables that are added to the request context, and corresponding code that breaks if such a variable already exists on the context.
  • Any other resources the component includes. Perhaps the issue is not with the component you are including three times, but with some component that the included one itself includes.
  • The things the component depends on. Does the component reference the necessary tag libraries for any tags it uses?
  • Scriptlets in the component that run code. Move those to tags and use tag libraries to get the Java code out of the JSP.

The JSP code you put in this example otherwise looks fine to me, so really it would require posting the component code to give a more detailed answer to a specific root cause.