Query Autocomplete Datasource

Available since version 2.5.0/3.1.0

Purpose

Query autocomplete datasource lets you build your autocomplete list using an XPath query.

How to Use

Component setup

Setup your component dialog and the autocomplete widget described in the documentation here.

  • Add a predicates String array property to the autocomplete widget node
  • Add a displayProperty String property to the autocomplete widget node
  • Add a datasource node to the autocomplete widget node.
  • Add an options node to the autocomplete widget node.
<autocomplete
        jcr:primaryType="nt:unstructured"
        sling:resourceType="granite/ui/components/foundation/form/autocomplete"
        fieldLabel="Autcomplete"
        name="./autocomplete"
        displayProperty="jcr:content/jcr:title"
        predicates="[type=cq:Page,path=/content/geometrixx,property=jcr:content/sling:resourceType,property.value=geometrixx/components/homepage]">
        <datasource
                jcr:primaryType="nt:unstructured"
                sling:resourceType="acs-commons/granite/ui/components/form/queryautocomplete/datasource" />
        <options
                jcr:primaryType="nt:unstructured"
                sling:resourceType="granite/ui/components/foundation/form/autocomplete/list" />
       </autocomplete>

Example Dialog

In the example below, the “Autocomplete” node will show results of the query generated by the xpath query.

/jcr:root/content/geometrixx//element(*, cq:Page) [jcr:content/@sling:resourceType = 'geometrixx/components/homepage']

The query is generated from using the predicate map:

type=cq:Page
path=/content/geometrixx
property=jcr:content/sling:resourceType
property.value=geometrixx/components/homepage

which is defined by the “predicates” property on the widget node.

<?xml version="1.0" encoding="UTF-8"?>
   <jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:sling="http://sling.apache.org/jcr/sling/1.0" jcr:primaryType="nt:unstructured" jcr:title="List" sling:resourceType="cq/gui/components/authoring/dialog" helpPath="en/cq/current/wcm/default_components.html#List">
      <content
      		jcr:primaryType="nt:unstructured"
      		sling:resourceType="granite/ui/components/foundation/container">
         	<layout
         		jcr:primaryType="nt:unstructured"
         		sling:resourceType="granite/ui/components/foundation/layouts/fixedcolumns" margin="{Boolean}false" />
         	<items
         		jcr:primaryType="nt:unstructured">
            	<column
            		jcr:primaryType="nt:unstructured"
            		sling:resourceType="granite/ui/components/foundation/container">
               	<items
               		jcr:primaryType="nt:unstructured">
                  		<autocomplete
                  			jcr:primaryType="nt:unstructured"
                  			sling:resourceType="granite/ui/components/foundation/form/autocomplete"
                  			fieldLabel="Autocomplete"
                  			name="./autocomplete"
                  			displayProperty="jcr:content/jcr:title"
                  			predicates="[type=cq:Page,path=/content/geometrixx,property=jcr:content/sling:resourceType,property.value=geometrixx/components/homepage]">
                     		<datasource
                     			jcr:primaryType="nt:unstructured"
                     			sling:resourceType="acs-commons/granite/ui/components/form/queryautocomplete/datasource" />
                     		<options
                     			jcr:primaryType="nt:unstructured"
                     			sling:resourceType="granite/ui/components/foundation/form/autocomplete/list" />
                  </autocomplete>
               </items>
            </column>
         </items>
      </content>
   </jcr:root>
Please report any issues with the Feature or documentation on the ACS AEM Commons GitHub Issue tracker.