Is it possible to access pageProperties from a datasource?

Avatar

Avatar
Give Back
Level 1
alvarof55440963
Level 1

Like

1 like

Total Posts

10 posts

Correct reply

0 solutions
Top badges earned
Give Back
Validate 1
Boost 1
View profile

Avatar
Give Back
Level 1
alvarof55440963
Level 1

Like

1 like

Total Posts

10 posts

Correct reply

0 solutions
Top badges earned
Give Back
Validate 1
Boost 1
View profile
alvarof55440963
Level 1

11-10-2018

Hi folks. Hope you are doing great.

So this is my problem. I need to dynamically load the options for a select item in a component dialog based on a page property. So I was planning to create a datasource that would read the page properties and then set the select options based on the value of the property. The problem is that if I try to access pageProperties or currentPage it is always null.

Is there a way to actually read page properties from a datasource?

I have my select in the component dialog like this:

<options

           jcr:primaryType="nt:unstructured"

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

           fieldLabel="Options"

           name="./options">

           <datasource

                  jcr:primaryType="nt:unstructured"

                  sling:resourceType="examples/datasources/test"/>

</options>

And my datasource:

<%@page session="false" import="

                  com.day.cq.commons.inherit.HierarchyNodeInheritanceValueMap,

                  com.day.cq.commons.inherit.InheritanceValueMap,

                  com.adobe.granite.ui.components.ds.DataSource,

                  com.adobe.granite.ui.components.ds.EmptyDataSource,

                  com.adobe.granite.ui.components.ds.SimpleDataSource,

                  com.adobe.granite.ui.components.ds.ValueMapResource,

                  org.apache.sling.api.resource.Resource,

                  org.apache.sling.api.resource.ResourceMetadata,

                  org.apache.sling.api.resource.ResourceResolver,

                  org.apache.sling.api.resource.ValueMap,

                  org.apache.sling.api.wrappers.ValueMapDecorator,

                  java.util.ArrayList,

                  java.util.HashMap,

                  java.util.Iterator,

                  java.util.List"%>

<%

%><%@taglib prefix="cq" uri="http://www.day.com/taglibs/cq/1.0" %><%

%><cq:defineObjects/><%

     //pageProperties always null here

%>

I'm using AEM 6.4

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,442 likes

Total Posts

3,318 posts

Correct reply

941 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,442 likes

Total Posts

3,318 posts

Correct reply

941 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

11-10-2018

Hi,

You can get the Page Property by getting page path and adapt to Node

Example :

  ResourceResolver resolver = request.getResourceResolver();

  String pagePath = request.getRequestPathInfo().getSuffix().replaceAll("/jcr:content/.*$", "");

  Node pageNode = resolver.getResource(pagePath).adaptTo(Node.class);

  String pageTitle= pageNode.getProperty("jcr:title").getString();

Answers (1)

Answers (1)

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,409 likes

Total Posts

12,671 posts

Correct reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,409 likes

Total Posts

12,671 posts

Correct reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

11-10-2018

I would use Java and HTL. You can read the page props using Page Manager API.

Using a Page object - you can obtain a lot of information about a given page.

Page ("The Adobe AEM Quickstart and Web Application.")

Then you can put that into a MAP on which a DataSource is based.

See this to learn how to use Java to create a DataSource to populate a Select:

Adobe Experience Manager Help | Using an WCMUsePojo class to populate an Experience Manager Touch UI...