英文:
AEM: Retrieve properties of all node of container node using query builder
问题
我是Adobe Experience Manager的新手。我正在使用Query Builder。以下是我尝试的查询,以搜索container_copy
节点的所有节点属性。
path=/content/pojoName/au/en/enquiry-form
type=cq:PageContent
1_property=jcr:content/root/container/container/container_copy
1_property.operation=exists
2_property=jcr:content/root/container/container/container_copy
2_property.value=singleText
这是我的CRXDE页面的快照:
英文:
I am newbie in Adobe Experience Manager. I am working on Query Builder. Here down is my query which is tried by me to search all node properties of container_copy
node.
path=/content/pojoName/au/en/enquiry-form
type=cq:PageContent
1_property=jcr:content/root/container/container/container_copy
1_property.operation=exists
2_property=jcr:content/root/container/container/container_copy
2_property.value=singleText
Here down is the snapshot of my page in CRXDE
答案1
得分: 1
你不需要搜索 type=cq:PageContent
。你可以搜索一个目标节点的 sling:resourceType
属性。因为CRX中的每个组件都会有这个属性。
如果你需要在 /content/pojoName/au/en/enquiry-form
下只找到必要的节点,请使用直接路径。更全局的路径可以用来查找更全局区域的组件,例如 /content/pojoName/au/en/
。
只需使用 container_copy
组件的 sling:resourceType
。
path=/content/pojoName/au/en/enquiry-form
1_property=sling:resourceType
1_property.value=PUT_VALUE_HERE
如果你需要子节点的属性,只需迭代子元素并获取属性。
Map map = new HashMap();
map.put("path", "/content");
map.put("1_property", "sling:resourceType");
map.put("1_property.value", "/resource/type/of/node");
Query query = builder.createQuery(PredicateGroup.create(map), session);
SearchResult result = query.getResult();
// 获取container_copy的属性
Optional.ofNullable(result.getResources)
.forEach(r -> r.getValueMap())
......
// 获取container_copy子节点的属性
Optional.ofNullable(result.getResources)
.forEach(r -> r.getChildren())
.forEach(r -> r.getValueMap())
......
英文:
You do not need to search for type=cq:PageContent
. You can search for a sling:resourceType
property for a targeted node. Since every component in CRX will have this property
If you need to find necessary nodes only under /content/pojoName/au/en/enquiry-form
use direct path. More global pass may be used to find components in more global area like /content/pojoName/au/en/
Just use the sling:resourceType
of container_copy
component.
path=/content/pojoName/au/en/enquiry-form
1_property=sling:resourceType
1_property.value=PUT_VALUE_HERE
If you need properties of child nodes, just iterate through the child element and get properties.
Map map = new HashMap();
map.put("path", "/content");
map.put("1_property", "sling:resourceType");
map.put("1_property.value", "/resource/type/of/node");
Query query = builder.createQuery(PredicateGroup.create(map), session);
SearchResult result = query.getResult();
//get properties of container_copy
Optional.ofNullable(result.getResources)
.forEach(r -> r.getValueMap())
......
//get properties of container_copy children
Optional.ofNullable(result.getResources)
.forEach(r -> r.getChildren())
.forEach(r -> r.getValueMap())
......
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论