Expand my Community achievements bar.

SOLVED

Getting a child node with their property Name

Avatar

Level 3

I have a container then layout then config then column then list I want to get those list property but node name changing again and again How can I extract the List name and there properties values without using name.

 

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @rohankalra ,

Try this,

Resource childResource = resourceResolver.getResource(child.getPath());
Node childNode = childResource.adaptTo(Node.class);
Node jcrContent = childNode.getNode("jcr:content");
NodeIterator childrenNodes = jcrContent.getNodes();

while(childrenNodes.hasNext()){
    Node next = childrenNodes.nextNode();
    String resourceType = next.getProperty("sling:resourceType").getString();
    if(resourceType.equals("your/custom/resource/property/path")) {
properties = childResource.adaptTo(ValueMap.class);
String propertyOne = properties.get("propertyOne", (String) null);
} }

View solution in original post

3 Replies

Avatar

Community Advisor

@rohankalra can you please share sample node structure how it's getting stored in crx ?

Avatar

Community Advisor

You can update your logic to use regex for checking the node name. For example it will always be in these format

list / list_NNNNNNNN_ / list_NNNNNNNN

Else you can go ahead with search based approach. You can write a query to fetch all list components based on sling:resourceType property.

Avatar

Correct answer by
Community Advisor

Hi @rohankalra ,

Try this,

Resource childResource = resourceResolver.getResource(child.getPath());
Node childNode = childResource.adaptTo(Node.class);
Node jcrContent = childNode.getNode("jcr:content");
NodeIterator childrenNodes = jcrContent.getNodes();

while(childrenNodes.hasNext()){
    Node next = childrenNodes.nextNode();
    String resourceType = next.getProperty("sling:resourceType").getString();
    if(resourceType.equals("your/custom/resource/property/path")) {
properties = childResource.adaptTo(ValueMap.class);
String propertyOne = properties.get("propertyOne", (String) null);
} }