【发布时间】:2017-03-24 10:41:22
【问题描述】:
下面是 datasource.jsp,用于将动态下拉列表添加到我的 customComponent 对话框中,我在我的 customComponent 中使用这个数据源,如下面提到的字段。 在这里,我的要求是当我的 customComponent 在任何页面(此页面具有 url)中使用时,需要将 url 值获取到下拉列表。所以在这里我需要使用我的 customComponent 的 currentPage url。
请帮助我获取我使用 customComponent 的页面 url 到这个数据源。
<%
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(fakeResourceList.iterator());
request.setAttribute(DataSource.class.getName(), ds);
%>
在我的 customComponent 对话框 content.xml 中,它使用上述数据源,因为它是 sling:resourceType。
<dataSourceTest
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/form/select"
fieldDescription="Provide ID"
fieldLabel="Anchor"
name="./datasourceTest">
<datasource
jcr:primaryType="nt:unstructured"
sling:resourceType="/apps/mysite/components/page/datasource"/>
</dataSourceTest>
【问题讨论】:
标签: aem