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?
Solved! Go to Solution.
Views
Replies
Total Likes
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.
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.
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
What adapter are you using in your model? Pls copy paste your model class here
@Model(adaptables = Resource.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL) public class UspModel { @HierarchicalPageProperty("usp") private String usp; public String getUsp() { return usp; } }
@Kishore_Kumar_ and one more thing how to write JUnit for this
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.
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);
Views
Likes
Replies