1
votes

I am having scenario in which i want to fetch all the values of a property under a specific path in AEM using QueryBuilder api. This property can have single or multivalued. Any help will be appreciated!!

2
if i understand correctly are you looking for the query which results the list of content path nodes ? OR to retrieve the property values alone for a specific content path ?. So far AFAIK the query builder is used to retrieve the content paths for a specific search matches.VAr

2 Answers

4
votes

Example that can help you. is below as it is just for illustration written in simple JSP scriptlets

 <%
Iterator<Resource> iter = resourceResolver.findResources("/jcr:root/content/geometrixx-outdoors//element(*, nt:unstructured)[(@imageRotate = '0' or @imageRotate = '1')]","xpath");
while (iter.hasNext()) {
    Resource child = iter.next();
    out.println("</br>"+child.getPath());
    Node node = child.adaptTo(Node.class);
    Property nProp = node.getProperty("imageRotate");

if(nProp.isMultiple()) // This condition checks for properties whose type is String[](String array)  
      {  
Value[] values = nProp.getValues();
    out.println(" :: This is a multi valued property ::");
    for (Value v : values) {
        out.println("</br>"+"Property Name = "+nProp.getName()+" ; Property Value= "+v.getString());
    }  
      }  
      else if(!nProp.getDefinition().isMultiple()){  
          out.println("</br>"+"Property Name = "+nProp.getName()+" ; Property Value= "+nProp.getString());
      }  
}
%>

Here i have used the Iterator<Resource> iter = resourceResolver.findResources(query,"xpath"); which can give you the query results which matches the imageRotate property under /content/geometrixx-outdoors/ path which consists combination of single and multivalued as shown in below screenshot.

CRX Node

1
votes

There is no direct way to fetch the properties using query builder api. I would suggest you to create a servlet resource, which requires a path and property name.

Fetch the jcr node using the given path via QueryBuilder. Then, you need to loop through the results to check the property of the nodes. You can access the multiple property values, once you have a node.