Expand my Community achievements bar.

Accessing deep child nodes (nested multifield)

Avatar

Level 2

I'm trying to fetch values from a nested multifield. The content is stored as follows in jcr:

bb5e25e2-cfc0-4b56-a05a-2de77f878c7f.png

The code below is adding the languages to the value map at the country level. ${country.locale} outputs the locale value for both nodes under languages. Any ideas?

private List<ValueMap> getLanguageLinks(String nodeName) {

     List<ValueMap> multifieldList = new ArrayList<ValueMap>();

     try {

          if (null != langSwitcherNode && langSwitcherNode.hasNode(nodeName)) {

               Node propertyNode = langSwitcherNode.getNode(nodeName);

               if (propertyNode.hasNodes()) {

                    NodeIterator iterator = propertyNode.getNodes();

                    while (iterator.hasNext()) {

                    Node childNode = iterator.nextNode();

                    multifieldList.add(resourceResolver.getResource(

                    childNode.getPath()).adaptTo(ValueMap.class));

                        if (childNode.hasNodes()){

                            Node languagesNode = childNode.getNode("languages");

                            if (languagesNode.hasNodes()){

                                NodeIterator childNodeIterator = languagesNode.getNodes();

                                while (childNodeIterator.hasNext()){

                                Node childLevel2Node = childNodeIterator.nextNode();

                                multifieldList.add(resourceResolver.getResource(

                                    childLevel2Node.getPath()).adaptTo(ValueMap.class));

                                }

                            }

                        }

                    }

          }

     }

} catch (RepositoryException e) {

LOG.error("RepositoryException", e);

}

return multifieldList;

}

2 Replies

Avatar

Level 10

What is happening when you use this component - any messages in the log?

Avatar

Level 2

Nothing specific to the component.

Even if I don't access the language node in the sightly template, it's creating x number of empty divs (however many languages have been added). It's iterating through it, but adding it at the wrong level.