Skip to main content

Posts

Showing posts from December, 2019

Generate id for AEM components

We all know that when we add an AEM component to a page, it creates the DOM structure on the pages based upon our HTL file.

Sometimes we require id attribute to be set in our div for n number of reasons. If we put id attribute in the HTL file itself then it will become static and if in include that component multiple times on the page, the same id will be repeated for all instance; which is not a neat solution.

Wouldn't it be nice if we have a mechanism to generate an id randomly and uniquely for each instance of the component on the page? In this post, we are going to do just that.

Hence, without further ado, let's get started -
Step #1 Create a component that will have the field for unique id. We are making this id editable as well to give more flexibility to the content authors. Below is the cq:dialog.xml file -

<?xml version="1.0" encoding="UTF-8"?><jcr:rootxmlns:sling="http://sling.apache.org/jcr/sling/1.0"xmlns:cq="http://www.d…

Workflows in AEM 05 - Trigger Workflow Programmatically

It is often needed to trigger a workflow programmatically. Hence, in this small post, we will see how we can easily do that.


packageorg.redquark.demo.core.servlets;importjava.io.IOException;importjava.util.Date;importjava.util.HashMap;importjava.util.Map;importjavax.servlet.Servlet;importorg.apache.sling.api.SlingHttpServletRequest;importorg.apache.sling.api.SlingHttpServletResponse;importorg.apache.sling.api.resource.ResourceResolver;importorg.apache.sling.api.servlets.HttpConstants;importorg.apache.sling.api.servlets.SlingSafeMethodsServlet;importorg.osgi.framework.Constants;importorg.osgi.service.component.annotations.Component;importorg.slf4j.Logger;importorg.slf4j.LoggerFactory;importcom.adobe.granite.workflow.WorkflowException;importcom.adobe.granite.workflow.WorkflowSession;importcom.adobe.granite.workflow.exec.WorkflowData;importcom.adobe.granite.workflow.model.WorkflowModel;/** * @author Anirudh Sharma */@Component(service=Servlet.class,property={Constants.SERVICE_DESCRIPTION…