Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Getting a child node with their property Name

Avatar

Level 2

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

0 Replies

Avatar

Community Advisor

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

Avatar

Level 8

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);
} }