Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

How to write modal class for inherited page property

Ronnie09
Level 4
Level 4

I have created one page property i.e usp

In sightly usp data is comming by 

${inheritedPageProperties.usp}

 

but I want to write the modal class to do the same with same functionality. How should I do that?

1 Accepted Solution
kishorekumar14
Correct answer by
Level 10
Level 10

Please try with SlingHttpServletRequest.class adaptable for below method.

 

@Inject
private InheritanceValueMap pageProperties;
String usp = pageProperties.getInherited("usp", "default");

and it will work without ACS common.

View solution in original post

6 Replies
kishorekumar14
Level 10
Level 10

You can use like below.

 

@Inject
private InheritanceValueMap pageProperties;
String usp = pageProperties.getInherited("usp", "default");

 

If you are using ACS Commons, we can use @HierarchicalPageProperty annotation.


https://adobe-consulting-services.github.io/acs-aem-commons/features/sling-model-injectors/hierarchi...

Ronnie09
Level 4
Level 4

It is working fine as per link using ACS Common.

 

I have one question I am using ACS COmmons therefore 

@Inject
private InheritanceValueMap pageProperties;
String usp = pageProperties.getInherited("usp", "default");

this would work?

I tried this it wasn't working but @HierarchicalPageProperty is working

kishorekumar14
Level 10
Level 10

What adapter are you using in your model? Pls copy paste your model class here 

Ronnie09
Level 4
Level 4
@Model(adaptables = Resource.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class UspModel {

    @HierarchicalPageProperty("usp")
    private String usp;

    public String getUsp() {
        return usp;
    }
}

 

@kishorekumar14 and one more thing how to write JUnit for this  

kishorekumar14
Correct answer by
Level 10
Level 10

Please try with SlingHttpServletRequest.class adaptable for below method.

 

@Inject
private InheritanceValueMap pageProperties;
String usp = pageProperties.getInherited("usp", "default");

and it will work without ACS common.

View solution in original post

sambasivara
Level 2
Level 2

You can also try this below snippet to access Inherited Page properties from Models

import com.day.cq.commons.inherit.InheritanceValueMap;
import com.day.cq.commons.inherit.HierarchyNodeInheritanceValueMap;

@Inject
Page currentPage;
...
InheritanceValueMap ivm = new HierarchyNodeInheritanceValueMap(currentPage.getContentResource());
String inheritedValueMyCustomProperty = ivm.getInherited("myCustomerProperty", String.class);
String inheritedValueJcrTitle = ivm.getInherited("jcr:title", String.class);