How to access component properties from a Java Class(AEM 5.6.1) | Community
Skip to main content
Sh1ju
Level 4
October 16, 2015
Solved

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

  • October 16, 2015
  • 5 replies
  • 15138 views

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.
Best answer by Feike_Visser1

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

edubey
Level 10
October 16, 2015

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

Sh1ju
Sh1juAuthor
Level 4
October 16, 2015

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.

Lokesh_Shivalingaiah
Level 10
October 16, 2015

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

Feike_Visser1
Adobe Employee
Feike_Visser1Adobe EmployeeAccepted solution
Adobe Employee
October 16, 2015

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");

smacdonald2008
Level 10
October 16, 2015
    A component  is only A node in the JCR. You use the JCR API to read node props using Java.