May 9, 2020
Estimated Post Reading Time ~

How to get node properties in JSP in AEM

Here is the procedure to get node properties in a JSP in AEM

<%@page session="false"%>
<%@ page import="java.util.Locale,
java.util.ResourceBundle,
javax.jcr.NodeIterator,
javax.jcr.Session,
javax.jcr.Node, javax.jcr.Value, javax.jcr.NodeIterator,
com.day.cq.commons.jcr.*" %>
<%@include file="/libs/foundation/global.jsp" %>

<%
javax.jcr.Session ses = resourceResolver.adaptTo(Session.class);
        //If you want to save anything to the node this session object (ses)is required.
String nodePath="/content/****";
Resource resources = slingRequest.getResourceResolver().getResource(nodePath);
         //Creating Node object using adaptTo mehtod.
Node rootNode = resources.adaptTo(Node.class);

*****Here is the node "rootnode", and now we can explore subnodes by using the root node and their properties.


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.