Hi Team,
We have a component using page properties in side it. When we use that component via reference component it is using the page properties of the page where that component dragged and dropped (It is working as per the Resource principles).
But we want that component to use the page properties of the page where it is included via reference component. We have a business use case to use the page properties of the page where it got included instead of the page where it got dragged and dropped.
We are using AEM 6.1 reference component.
Any inputs?
Solved! Go to Solution.
Views
Replies
Total Likes
Thank you all for responding. We have solved this in below way.
We changed the reference component code of sling include a little bit by adding a selector to it as below.
<sling:include path="<%= target %>" addSelectors="getCurrentPageProps"/></div>
As we added this selector. We are looking for this selector in our wcm use pojo class. If this selector presents then we are getting the page properties of the page where reference component is dragged and dropped other wise getting the page properties of where the actual component dragged and dropped.
String inhetitedProp1 = "";
if (getRequest().getRequestPathInfo().getSelectors().length > 0) {
//From current page props
InheritanceValueMap iProperties = new HierarchyNodeInheritanceValueMap(getCurrentPage().getContentResource());
inhetitedProp1 = iProperties.getInherited(property, null)
} else {
//from page props of where the component is included
inhetitedProp1 = getInheritedProperties().get(property)
}
Views
Replies
Total Likes
Try using resourcePage-object, that should do it.
Views
Replies
Total Likes
Thank you for responding.
Can you please elaborate that. How we can pass on the current page resource to the actual component via the reference component.
In reference component we are just sling inluding the content path.
Views
Replies
Total Likes
ResourcePage refers to the page containing your resource and is an instance of com.day.cq.wcm.api.Page, and resourceDesign is the design object for the resource page.
The resourcePage can be obtained using PageManager's #getContainingPage() as shown here.
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
...
@Override
protected void doGet(SlingHttpServletRequest slingRequest,
SlingHttpServletResponse slingResponse) throws ServletException, IOException {
ResourceResolver resourceResolver = slingRequest.getResourceResolver();
PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
Page resourcePage = pageManager.getContainingPage(slingRequest.getResource());
Designer designer = resourceResolver.adaptTo(Designer.class);
Design resourceDesign = designer.getDesign(resourcePage);
Reference Post:- servlets - Finding resourceDesign and resourcePage in Java for Adobe CQ - Stack Overflow
~kautuk
Views
Replies
Total Likes
Thank you all for responding. We have solved this in below way.
We changed the reference component code of sling include a little bit by adding a selector to it as below.
<sling:include path="<%= target %>" addSelectors="getCurrentPageProps"/></div>
As we added this selector. We are looking for this selector in our wcm use pojo class. If this selector presents then we are getting the page properties of the page where reference component is dragged and dropped other wise getting the page properties of where the actual component dragged and dropped.
String inhetitedProp1 = "";
if (getRequest().getRequestPathInfo().getSelectors().length > 0) {
//From current page props
InheritanceValueMap iProperties = new HierarchyNodeInheritanceValueMap(getCurrentPage().getContentResource());
inhetitedProp1 = iProperties.getInherited(property, null)
} else {
//from page props of where the component is included
inhetitedProp1 = getInheritedProperties().get(property)
}
Views
Replies
Total Likes
Views
Likes
Replies