title: Adobe CQ Components restricting child components
body: <p>I am trying to create a component for a simple accordion, where blocks of content are held under headings and only one heading is visible at a time. My preferred implementation uses two components, one to represent the whole accordion and a second component for a single entry.</p>
  
  <p>The idea is that a content author can pull the accordion in from the sidekick, then drop one or more accordion items into the accordion, but not allow any other components to be dropped here. The accordion items should only be able to be dropped into the accordion component and not within any other parsys.</p>
  
  <p>My problem is that currently it is possible to add other content into the accordion and add accordion items outside of the accordion.</p>
  
  <p>The first attempt to solve this was:</p>
  
  <pre><code>foobar/components/accordion
  foobar/components/accordion/accordion.jsp
  foobar/components/accordion/cq:editConfig
  foobar/components/accordion/dialog
  foobar/components/accordion/accordionitem
  foobar/components/accordion/accordionitem/accordionitem.jsp
  foobar/components/accordion/accordionitem/cq:editConfig
  foobar/components/accordion/accordionitem/dialog
  </code></pre>
  
  <p>These are the config files from this are:</p>
  
  <p><strong>accordion/.content.xml</strong></p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
      xmlns:cq="http://www.day.com/jcr/cq/1.0"
      xmlns:jcr="http://www.jcp.org/jcr/1.0"
      cq:isContainer="{Boolean}true"
      jcr:primaryType="cq:Component"
      jcr:title="Accordion"
      sling:resourceSuperType="foundation/components/parbase"
      allowedChildren="[*/accordion/accordionitem]"
      allowedParents="[*/parsys]"
      componentGroup="General"/&gt;
  </code></pre>
  
  <p><strong>accordion/_cq_editConfig.xml</strong></p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0"
      xmlns:jcr="http://www.jcp.org/jcr/1.0"
      cq:actions="[-,edit,-,delete]"
      cq:layout="editbar"
      jcr:primaryType="cq:EditConfig"&gt;
      &lt;cq:listeners
          jcr:primaryType="cq:EditListenersConfig"
          aftercopy="REFRESH_PAGE"
          afterdelete="REFRESH_PAGE"
          afterinsert="REFRESH_PAGE"/&gt;
  &lt;/jcr:root&gt;
  </code></pre>
  
  <p>The dialog is blank and exists only so that the component will appear in the sidekick.</p>
  
  <p>accordion.jsp simply includes the foundation parsys.</p>
  
  <p><strong>accordion/accordionitem/.content.xml</strong></p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
      xmlns:cq="http://www.day.com/jcr/cq/1.0"
      xmlns:jcr="http://www.jcp.org/jcr/1.0"
      jcr:primaryType="cq:Component"
      jcr:title="Accordion Item"
      sling:resourceSuperType="foundation/components/parbase"
      allowedParents="[*/accordion]"
      componentGroup="General"/&gt;
  </code></pre>
  
  <p>The accordion item dialog takes in the title.  The editConfig simply adds the toolbar, but no listeners.</p>
  
  <p>accordionitem.jsp outputs the title taken from the dialog and has a parsys.</p>
  
  <p>My problem seems to be that the parsys aren't using the rules for the accordion and accordionitem components. Instead they seem to inherit from the next parsys up instead, unless overwritten.</p>
  
  <p>I can set the components correctly by using edit mode on the page and selecting the appropriate components, but that sets the information against the template, meaning I need to perform the same configuration for every page template. What I want is to have it defined in the component definition instead so that it exists once.</p>
  
  <p>After first writing the components I found this blog, which describes exactly the same scenerio: <a href="http://jenikya.com/blog/2012/03/cq5-accordion-component.html" rel="noreferrer">http://jenikya.com/blog/2012/03/cq5-accordion-component.html</a></p>
  
  <p>Using that as I reference, I tried adding an extension of parsys to use within accordion.jsp instead. This made no difference to the code, so even my custom parsys allowed components other than accordion item to be added.</p>
  
  <p>Any guidance on either what is wrong or other approaches to take will be greatly appreciated.</p>