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
BedrockMission!

Learn More

View all

Sign in to view all badges

How can we get currentPage url into Datasource

Avatar

Avatar
Level 1
satishkumark530
Level 1

Likes

0 likes

Total Posts

3 posts

Correct Reply

0 solutions
View profile

Avatar
Level 1
satishkumark530
Level 1

Likes

0 likes

Total Posts

3 posts

Correct Reply

0 solutions
View profile
satishkumark530
Level 1

16-03-2017

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]

Accepted Solutions (0)

Answers (1)

Answers (1)

Avatar

Avatar
Boost 3
Level 1
Szalam
Level 1

Likes

3 likes

Total Posts

17 posts

Correct Reply

0 solutions
Top badges earned
Boost 3
Boost 1
View profile

Avatar
Boost 3
Level 1
Szalam
Level 1

Likes

3 likes

Total Posts

17 posts

Correct Reply

0 solutions
Top badges earned
Boost 3
Boost 1
View profile
Szalam
Level 1

16-03-2017

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.