Skip to main content
Sh1ju
Level 4
Oct 16, 2015 2:28 AM UTC
Solved

How to access component properties from a Java Class(AEM 5.6.1)

Can I get some code for fetching component properties from a java class.

I'm  working on a component which requires some properties that the user sets during run time.

Initially, I was simply using a properties.get('employeename') to fetch this property from my component(JSP), but I'm trying collect this value from a java bean.

How to fetch this property 'employeename' (which is set during runtime on my component) within my Java code?

We can achieve this by using third party AEM frameworks like Slice,Bedrock etc.But I didn't want these frameworks.

Refer : http://code.citytechinc.com/bedrock/component-framework.html​

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Feike_Visser1
Feike_Visser1Accepted solution
Adobe Employee
Oct 16, 2015 2:28 AM UTC

I would say from to use as much as you can the ValueMap-approach.

Page page = currentPage;

ValueMap props = page.getContentResource("componentName").adaptTo(ValueMap.class);

String title = props.get("jcr:title", "default value");

5 replies

smacdonald2008
Level 10
Oct 16, 2015 2:28 AM UTC
    A component  is only A node in the JCR. You use the JCR API to read node props using Java. 
Translate
Feike_Visser1
Adobe Employee
Feike_Visser1Adobe EmployeeAccepted solution
Adobe Employee
Oct 16, 2015 2:28 AM UTC

I would say from to use as much as you can the ValueMap-approach.

Page page = currentPage;

ValueMap props = page.getContentResource("componentName").adaptTo(ValueMap.class);

String title = props.get("jcr:title", "default value");

Translate
Lokesh_Shivalingaiah
Level 10
Oct 16, 2015 2:28 AM UTC

This is one of the way

Page page = currentPage;

Node node = page.getContentResource("componentName").adaptTo(Node.class);

String title = node.getProperties("jcr:title").getString();

and similarly fetch all any properties from the component

Translate
Sh1ju
Sh1juAuthor
Level 4
Oct 16, 2015 2:28 AM UTC

I'm  working on a component which requires some properties that the user sets during run time.

Initially, I was simply using a properties.get('employeename') to fetch this property from my component(JSP), but I'm trying collect this value from a java bean.

How to fetch this property 'employeename' (which is set during runtime on my component) within my Java code?

We can achieve this by using third party AEM frameworks like Slice,Bedrock etc.But I didn't want these frameworks.

Translate
edubey
Level 10
Oct 16, 2015 2:28 AM UTC

Hi, 

Its seems like you want to read properties from java class Refer here [1]

[1] https://helpx.adobe.com/experience-manager/using/programmatically-accessing-cq-content-using.html

Please refer above link for fetching properties.

Let me know if it doesn't help

Translate