How to get the property of a JCR content node in AEM

Posted By: Matpal Media - 12:52 PM
Following JSP can be used to read the jcr property of a node. Here we will use jcr property “jcr:lastModifiedBy” as an example –
<%--
 This JSP explains how to read a property of a content node
 Example property is "jcr:lastModifiedBy" 
--%>

<%@include file="/libs/foundation/global.jsp"%><%
%><%@page session="false" %>
<%@ page import="java.util.Iterator,
     com.day.cq.wcm.api.PageFilter,
  com.day.cq.wcm.api.Page,
  com.day.cq.wcm.api.PageManager,
  com.day.cq.wcm.api.WCMMode,
  org.apache.sling.api.resource.Resource,
  javax.jcr.Node,com.day.cq.replication.Replicator" %>


<%

String nodePath = "/content/community-components/en/comments/jcr:content/content/title";

try
{
Node node = null;
NodeIterator nodes =null;
String result="";
resource = slingRequest.getResourceResolver().getResource(nodePath);

    if(resource != null)
    {
    node = resource.adaptTo(Node.class);
    
        if(node.hasProperty("jcr:lastModifiedBy"))
                 {
                    result=node.getProperty("jcr:lastModifiedBy").getValue().getString();
                    out.print(result);
    
                 }

    }
}

catch(Exception e) 
{
out.print(e);
}
%>

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.