How to read properties values on a certain node in CQ5

While working with CQ5 you will always see nodes that have properties configured over them which can contain values. The values are of different format. Some can be in String or String [] or may be Date at some time. If  you have resolved the resource at certain path  and the resource name is resolvedResource. Then you can simply fetch the values like

ValueMap valueMap = resolvedResource.adaptTo(ValueMap.class); // Refer to sling adapters in Felix console to know more.
String propValue = valueMap.get(“propertyName”,String.class);  // The second parameter can be String array or date, otherwise the default value is always string, if you retrieve a string then you will have to do conversion on your own. The other alternative is to do iteration over the Node.

Node nodeName =  resolvedResource.adaptTo(Node.class);

Refer to this post here to read the properties


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s