Question

I would like to apply some java function on CQ5 dialogs. In the first step I search for dialog xml files in myComponent folder as follow:

NodeIterator tabRequiredFields = getQueryResult("/jcr:root/apps/myProject/pages/myComponent/dialog/jcr:root")

But this Query does not supply any results. crx Xpath tool does not show any result too see the follwoing picture:

enter image description here

my /jcr:root/apps/myProject/pages/myComponent/dialog.xml looks like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
        jcr:primaryType="cq:Dialog"
        stateful="false"
        title="Test"
        .....>
       <items
        jcr:primaryType="cq:Widget"
        xtype="panel">
        ...
        ......
       </items>
      .....
   </jcr:root>

I can access items as follow

NodeIterator tabRequiredFields = getQueryResult("/jcr:root/apps/myProject/pages/myComponent/dialog/items")

This works fine. My Question is: why for jcr:root? how to check, if jcr:root exists?

Was it helpful?

Solution

XML element named jcr:root from the dialog.xml doesn't create jcr:root node in the repository. It's a special, reserved identifier and CRX Package Manager puts all properties and subnodes of this element into a node which name is the same as name of the file without extension (in your case it'll be dialog).

If it's not clear, use CRX DE, open /apps/myProject/pages/myComponent and see what you can find there. That's why you should add /dialog rather than /jcr:root to the end of your path.

If you want to find all dialogs, use the primary type cq:Dialog, as rakhi4110 suggests. Following query:

/jcr:root/apps/myProject/pages//element(*, cq:Dialog)

will return all dialogs from /apps/myProject/pages (and descendants).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top