Tuesday, 12 February 2019

How to load author client libraries only in the edit mode in sightly?

The below code loads the client library only in the preview and edit mode.

<sly data-sly-test="${wcmmode.preview || wcmmode.edit}" data-sly-call="${clientLib.all @ categories='category.name'}"/>

Thursday, 7 February 2019

Creating system user | How to create system user in aem cq

System users help us play with the aem reources, make changes and commmit it programmatically. Creating a system user involves couple of steps, the same is illustrated below.

Step 1:: Access crx explorer from the link http://localhost:4502/crx/explorer/index.jsp.

Step 2:: In order to create system user, you should have logged in with the Administrators credentials. Click on login on the crx explorer dashboard.

Step 3:: Click the option called "User Administartion". This now opens up a new window , Click "Create system user" to create one.

Step 4::  Fill the details :: User iD -> system(this is just the user id of the user, can be any name).
Enter the intermediate path: /home/users/system

Step 5:: Select the small green tick to complete the step.

Congratulations!!! You just created a system user.




Monday, 10 September 2018

AEM Workflows And Launchers - A powerful tool to automate process.

In this era of automation, the demand is to enforce the process to happen without manual intervention. In order to achieve this workflows and launchers play a major role in achieving it.

Workflows
Workflow allows the developers to automate the steps to be carried out. It allow us to manipulate the jcr resources on the go. AEM provides many inbuilt workflows, but a developer also has the flexibility to create a custom workflow.

The workflow dashboard can be accessed from the below url.
http://localhost:4502/libs/cq/workflow/content/console.html

The state of the workflow can be traced from the Archive tab from the workflow console. Worklow exhibits the following state.

  • Running
  • Completed
  • Suspended
  • Aborted
  • Stale
Launchers
In order to fire the workflows automatically, launcher is the tool that can be of help. The launchers fire the workflow based on the event type, node type, path, etc. For example:: A new property can be set to the page created. In the launcher dialog we have the configuration to select the workflow to associate with it.

Workflow Sessions
The workflow sessions can be very useful to process the payloads. Below code can help the developers fetch the session in a workflow.
session = workflowSession.adaptTo(javax.jcr.Session.class);
session = workflowSession.getSession();
The syntax code snippet to create a custom workflow process is discussed in the below blog.
http://anshumankumaraem.blogspot.com/2017/11/whats-new-in-aem-63.html

What is a payload in workflow ??
This is the resource on which the workflow is subjected. Ex: A Page.
Below code snippet can help fetch the payload in the workflow.
WorkflowData workflowData = workItem.getWorkflowData();
String payLoadPath = (String) workflowData.getPayload();

Thursday, 26 April 2018

How to use System user to access the crx repository?

System user is configured in the user mapper configuration in the felix console. In the below example datawrite is the system user.
The below code demonstrates the way in which we can use a system user to access the repository to make changes to it.

Map<String, Object> paramsMap = new HashMap<String, Object>();
paramsMap.put(ResourceResolverFactory.SUBSERVICE, "datawrite");
ResourceResolver resourceResolver = null;
resourceResolver = resourceResolverFactory.getServiceResourceResolver(paramsMap);
Resource res = resourceResolver.getResource("<Path in the repository>");
//Write logic to make changes to the resource.
//Then commit the changes done to the repository.
res.getResourceResolver().commit();

Wednesday, 11 April 2018

Event Handler and Event Listener

Event Handler:: The sling level events can be captured by implementing the event handler interface. A property called EventConstants.EVENT_TOPIC has to be fined which signifies what event has to be captured. In this case the event handler catches the page being created. handleEvent(Event event)  method is implemented which can have the code to implement the business logic. Like we cna set a new property on creation of a page
 Example::
@Component(service = EventHandler.class, immediate = true, property = {
Constants.SERVICE_DESCRIPTION + "=Your Description here",
EventConstants.EVENT_TOPIC + "=com/day/cq/wcm/core/page" })

Event Listener:: The event handling at the jcr level can be captured by implementing the event listener interface. It is mostly concerned about the low level jcr events like node or property movement, addition, deletion etc.  The onEvent(EventIterator events) can be used to include the business logic, like deleting some property on node being copied. Observation manager can be used is used to listen to listen to events like Event.NODE_ADDED.

Example:: observationManager.addEventListener(this, Event.NODE_ADDED, path, true, null, null, false); :: In this example the event listener listens to the node being added to the jcr repository.


Wednesday, 28 February 2018

How to include a component

Add these two property to the node.

sling:resourceType="granite/ui/components/foundation/include"
path="/path/to/the/component"

Wednesday, 17 January 2018

Vault Clipse Set up

Hello, There are some steps that has to be followed to set up vault clipse to synchronize the content between eclipse and aem crx.

Note:: Your AEM jar can be anywhere in the file system of your computer. The below paths are just for reference.
Step 1::

Download the 2.4 version of file vault from the below link.
https://www.adobeaemcloud.com/content/companies/public/adobe/filevault/filevault.html

For my windows the below archive worked perfect
 vault-cli-2.4.40-bin.tar.gz
Download as .tar.gz archive

Step 2::

*Copy the downloaded archive at C:\Users\anshuman\AEM\crx-quickstart\opt\filevault\vault-cli-2.4.40-bin.tar.gz

*This is the crx folder generated when we execute the AEM jar

*unzip the file here

Step 3::

Now download vault clipse 2.4 form eclipse market place and set vault directory one level above bin.

Vault Directory::C:\Users\anshuman\AEM\crx-quickstart\opt\filevault\vault-cli-2.4.40-bin.tar\vault-cli-2.4.40

You can also change your temporary directory to
C:\Temp

Step 4::

Also set the "path" of the system environment variable to
C:\Users\anshuman\AEM\crx-quickstart\opt\filevault\vault-cli-2.4.40-bin.tar\vault-cli-2.4.40\bin

Note:: If the export or import operation is throwing out some error then try to delete everything from the temporary folder.

Import:: Pushes the content from eclipse to Crx.
Export:: Pulls the content from Crx to eclipse.

Tuesday, 16 January 2018

How to fetch the values stored at page's jcr:content node

This fetches the page name.
<h1>${currentPage.Name}</h1>

This fetches title of the page.
<h2>${pageProperties['jcr:title']}</h2>

How to include clientlib in the html file using sightly

The client library can be included by using the below code::
The first line declares a clientlib object, which is implemented as a template. Then css or js is called based on the categories.

<sly data-sly-use.clientlib="/libs/granite/sightly/templates/clientlib.html"></sly>
<sly data-sly-call="${clientlib.css @ categories='category.name'}"></sly>

To call css
data-sly-call="${clientlib.js @ categories='clientlib1,clientlib2'}" 

data-sly-call="${clientlib.css @ categories='clientlib1,clientlib2'}"

To call both css and js
data-sly-call="${clientlib.all @ categories='clientlib1,clientlib2'}"/>

Monday, 4 December 2017

Tag Field Vs Tags Picker

It is always recommended to use tag field (/libs/cq/gui/components/coral/common/form/tagfield) over tag picker, since the tagpicker is deprecated from AEM 6.3. The tagfield can be put into validation for a mandatory field by simply adding a property required(Boolean) true.

The ootb component is very easy to be overlayed and hence customize its functionality. Render.jsp is responsible for the logic and rendering(visual) of the tags.

extraClientlibs Usage

The purpose of property "extraClientlibs" is to selectively load client library for a dialog. This prevents the unnecessary load o...