April 10, 2020
Estimated Post Reading Time ~

Some Quick Notes on AEM

How to get a Resource when we have a node path?

In Java:

@Reference
private ResourceResolverFactory resourceResolverFactory;

ResourceResolver resolver=null;

resolver = resourceResolverFactory.getAdministrativeResourceResolver(null);

Resource res=null;
res= resolver.getResource("PATH");


In JSP:

Resource res= resourceResolver.getResource("PATH");

How to get a Node, Get node property, Add/Update node property?

Node node = res.adaptTo(Node.class);

Get propoerty:

String prop= node.getProperty("Prop_name").getValue().getString();

String prop = node.setProperty("Prop_name","Value");
Note: Don't forget to save the session when the node is updated.

Update Node using PersistableValueMap:

Resource resource = resolver.getResource("Node Path");
if(resource !=null)
{
PersistableValueMap valueMap= resource.adaptTo(PersistableValueMap.class);
valueMap.put("propname","value");
valueMap.save();
}

How to get a JackRabbit session in the Workflow?

final JackrabbitSession jackrabbitSession = (JackrabbitSession) wfsession.getSession();
UserManager userManager = jackrabbitSession.getUserManager();


By aem4beginner

No comments:

Post a Comment

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