Expand my Community achievements bar.

SOLVED

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

Avatar

Level 4

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

desktop_exl_promo_600x100_weempoweryou.png

1 Accepted Solution

Avatar

Correct answer by
Employee

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

View solution in original post

5 Replies

Avatar

Level 10

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

Avatar

Level 4

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.

Avatar

Level 10

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

Avatar

Correct answer by
Employee

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

Avatar

Level 10
    A component  is only A node in the JCR. You use the JCR API to read node props using Java.