How get current selected page path in datasource sling model
Hi,
I have a custom dropdown in page properties Basic Tab, This dropdown show while creating new page. I want take the current selected page and get values from OSGi service to show the drop.
How I can get the current page path in datasource sling model?
Below is my code.
1. DatasourceModel.java
@Model(adaptables = SlingHttpServletRequest.class)
public class DatasourceModel {
private static final Logger LOG = LoggerFactory.getLogger(DatasourceModel.class);
@Self
protected SlingHttpServletRequest request;
@586265
@required
@SlingObject
private ResourceResolver resourceResolver;
@PostConstruct
public void init(){
// get List of values from OSGi service by passing current page(parent page) path
ValueMap valueMap = new ValueMapDecorator(new HashMap<>());
valueMap.put("text", "textOne");
valueMap.put("value", "valueOne");
List<Resource> resourceList = new ArrayList<>();
resourceList.add(new ValueMapResource(resourceResolver,
new ResourceMetadata(), "nt:unstructured", valueMap));
DataSource ds = new SimpleDataSource(resourceList.iterator());
request.setAttribute(DataSource.class.getName(),ds);
}
}2. datasource.html
<sly data-sly-use="com.mysite.core.models.DatasourceModel"/>3. dialog.xml
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:granite="http://www.adobe.com/jcr/granite/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
jcr:primaryType="nt:unstructured"
jcr:title="Page"
sling:resourceType="cq/gui/components/authoring/dialog"
extraClientlibs="[cq.common.wcm,core.wcm.components.page.v3.editor,cq.wcm.msm.properties,granite.contexthub.configuration,cq.siteadmin.admin.properties,core.wcm.components.image.v3.editor]"
helpPath="https://www.adobe.com/go/aem_cmp_page_v3"
mode="edit"
trackingFeature="core-components:page:v3">
<content
granite:class="cq-dialog-content-page"
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/container">
<items jcr:primaryType="nt:unstructured">
<tabs
granite:class="cq-siteadmin-admin-properties-tabs"
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/tabs"
size="L">
<items jcr:primaryType="nt:unstructured">
<basic
jcr:primaryType="nt:unstructured"
jcr:title="Basic"
sling:resourceType="granite/ui/components/coral/foundation/fixedcolumns">
<items jcr:primaryType="nt:unstructured">
<column
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/container">
<items jcr:primaryType="nt:unstructured">
<mydropdown
cq:showOnCreate="{Boolean}true"
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/select"
fieldLabel="My Dropdown"
name="./mydropdown">
<datasource
jcr:primaryType="nt:unstructured"
sling:resourceType="/apps/mysite/components/datasource"/>
</mydropdown>
</items>
</column>
</items>
</basic>
</items>
</tabs>
</items>
</content>
</jcr:root>
