Expand my Community achievements bar.

Who Me Too'd this topic

Avatar

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]

Who Me Too'd this topic