April 10, 2020
Estimated Post Reading Time ~

How to Get Node Properties?

<%@page import="javax.jcr.Session,javax.jcr.Node,org.apache.sling.jcr.resource.JcrResourceUtil,
com.day.cq.tagging.Tag,
com.day.cq.tagging.TagManager,com.day.cq.tagging.JcrTagManagerFactory"
%>

<%
//Node node;

Session session = slingRequest.getResourceResolver().adaptTo(Session.class);
TagManager tagManager = sling.getService(JcrTagManagerFactory.class).getTagManager(session);
Tag tag = tagManager.resolve("/apps/webexample_siva/components/content/contact"); 
//specify the path which you want to get
Node node = tag.adaptTo(Node.class);
String name= node.getName();

%>
//Iterate node properties and displays node property name and value

<%
for(PropertyIterator propeIterator = node.getProperties() ; propeIterator.hasNext();)
{
Property prop= propeIterator.nextProperty();
if(!prop.getDefinition().isMultiple())
{

%>

<%=prop.getName() %> & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;
<%=prop.getString() %> < br / >
 <%

}

}
%>


By aem4beginner

No comments:

Post a Comment

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