Expand my Community achievements bar.

How to retrieve the node structure of the page in the UI giving the path of the page in aem6.3?

Avatar

Level 2

I need to retrieve the internal node structure(which is nothing but including the node structure of how the components of the page are stored in the JCR) of the page and render the UI giving the path of the page in aem6.3. Can anyone help me out?

10 Replies

Avatar

Level 9

Try this String nodePath = "/content/community-components/en"; try { Node node = null; NodeIterator nodes =null; String result=""; resource = slingRequest.getResourceResolver().getResource(nodePath);     if(resource != null)     {     node = resource.adaptTo(Node.class);     NodeIterator nodeItr = node.getNodes();             while(nodeItr.hasNext())                 {                 Node cNode = nodeItr.nextNode();                 result=node.getProperty("jcr:primaryType").getValue().getString();                 out.print(result);                 }     } } catch(Exception e) { out.print(e); } or http://keysandstrokes.info/aem-code-snippets-read-child-nodes-aem/

Avatar

Level 2

Can you please let me know whether retrieval of the data in json format which is achieved using javascript use-api in aem6.3?

Avatar

Level 9

use the below js to get page nodes use(function () { var pageName = currentPage.name; var title = currentPage.properties.get("jcr:title"); var resourceName = granite.resource.name; var resourceTitle = properties.get("jcr:title"); return { pageName: pageName, title: title, resourceName: resourceName, resourceTitle: resourceTitle }; }); refer to examples here https://helpx.adobe.com/experience-manager/htl/using/use-api-javascript.html

Avatar

Level 10

What business case are you supporting with this information. Purhaps there is another way to achieve your  requirements.

Avatar

Level 2

Screen Shot 2018-02-09 at 11.49.34 AM.png

In the above image 'fr' is the page while giving the path of the page in the UI, it should retrieve the nodes and properties of them in a particular format(preferably in json), Is there anyways to do it using javascript use apis or anyother means?

Avatar

Level 3

Hi Malarvizhi Saravanan​ :

I would suggest you to use AEM's Content Services to achieve what you want.

I is the best solution to your problem, giving you granular control over the data you would like to expose via the API.

Cheers,

Jagjeet

AEM Forms Blog

Avatar

Level 2

Is there any other means to do with JCR Node API to achieve this?

Avatar

Level 9

https://docs.adobe.com/docs/en/spec/jsr170/javadocs/jcr-1.0/javax/jcr/NodeIterator.html

<%

String nodePath = "/content/community-components/en";

try

{

Node node = null;

NodeIterator nodes =null;

String result="";

resource = slingRequest.getResourceResolver().getResource(nodePath);

   if(resource != null)

  {

  node = resource.adaptTo(Node.class);

  NodeIterator nodeItr = node.getNodes();

  

   while(nodeItr.hasNext())

  {

  Node cNode = nodeItr.nextNode();

  result=node.getProperty("jcr:primaryType").getValue().getString();

  out.print(result);

  }

  }

}

catch(Exception e)

{

out.print(e);

}

%>

Avatar

Level 2

You can create the structure using  "infinity.json". For Example, if the page path is "/content/we-retail/ca/en/men" you can get the data from "/content/we-retail/ca/en/men.infinity.json" by using javascript(ajax call)