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

How can we get currentPage url into Datasource

satishkumark530
Level 1
Level 1

Below is datasource.jsp for adding dynamic dropdown into my customComponent dialog, I'm using this datasource in my customComponent as below mentioned <dataSourceTest> field.

Here my requirement is need to get url values to dropdown when my customComponent used in any page(this page having urls). So here i need that currentPage url where i have used my customComponent.

Please help me to get that page url where i have used my customComponent to this datasource.

<%

request.setAttribute(DataSource.class.getName(), EmptyDataSource.instance()); 

ResourceResolver resolver = resource.getResourceResolver();

//Create an ArrayList to hold data

List<Resource> fakeResourceList = new ArrayList<Resource>();

ValueMap vm = null;

Resource childResource = resourceResolver.getResource(currentPage.getPath()+"/jcr:content/node/path");

if(childResource!=null){

    Node childNode = childResource.adaptTo(Node.class);

    Node childLinks = childNode.getNode("childnode");

     if(childLinks!=null){    

    NodeIterator childrenNodes = childLinks.getNodes();

          while(childrenNodes.hasNext()) {

             vm = new ValueMapDecorator(new HashMap<String, Object>());

             Node next = childrenNodes.nextNode();

             String label = next.getProperty("label").getValue().getString();

             String path = next.getProperty("url").getValue().getString();

             vm.put("text",label);

             vm.put("value",path.substring(1));       

             fakeResourceList.add(new ValueMapResource(resolver, new ResourceMetadata(), "nt:unstructured", vm)); 

         }

   }

} else {

    vm = new ValueMapDecorator(new HashMap<String, Object>());

    vm.put("text","NoValue");

    vm.put("value","");

    fakeResourceList.add(new ValueMapResource(resolver, new ResourceMetadata(), "nt:unstructured", vm));

}

DataSource ds = new SimpleDataSource(anchorResourceList.iterator());

request.setAttribute(DataSource.class.getName(), ds);

%>

customComponent dialog content.xml which is using above datasource as it's sling:resourceType.

<dataSourceTest

     jcr:primaryType="nt:unstructured"

     sling:resourceType="granite/ui/components/foundation/form/select"

     fieldDescription="Provide a unique ID to support deeplinking"

     fieldLabel="Anchor"

     name="./datasourceTest">

     <datasource

          jcr:primaryType="nt:unstructured"

          sling:resourceType="/apps/nvidiaGDC/components/page/datasource"/>

</dataSourceTest>

[Moved from Forum comments to AEM forum - moderator]

0 Replies
Szalam
Level 2
Level 2

What Adobe software are you using? This post is in the Forum Comments forum (which is for issues regarding these Adobe forums themselves). If you let us know what software you need help with, a moderator can move your thread to the appropriate forum.

zahid15001577
Level 1
Level 1
I am having similar issues. Were you able to resolve this? If yes, would you be able to share the solution?