AEM:使用查询构建器检索容器节点的所有节点属性。

huangapple go评论46阅读模式
英文:

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页面的快照:

AEM:使用查询构建器检索容器节点的所有节点属性。

英文:

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

AEM:使用查询构建器检索容器节点的所有节点属性。

答案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())
 ......

huangapple
  • 本文由 发表于 2023年5月29日 15:44:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76355507.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定