Saturday, 26 March 2016

Implement DataSource for drop down using Sightly AEM 6.1

In Touch UI component, DataSource is very useful when it comes populate drop down dynamically. This article will help you to understand how datasource can be used with Sightly and leaving JSP behind.
Let’s get started with authoring…
Sightly DataSource Component Authoring
Component contains a simple drop down, values for this will be populate dynamically using DataSource.

Friday, 25 March 2016

Populate Tags based on Selection in Pathfield – Classic UI

This simple use case has been taken from AEM community, I thought an article for this would really help people who are looking for this or may need in future.
Component Overview
We have two field, one is pathfield (which helps to browse repository) and another a tag input field. Author selects an asset from pathfield and based on the the selection Tag input field is populated with tags available for selected assets.
Authoring Experience
Component dialogComponent

In-container testing for AEM projects

Nowadays it’s easier than ever to encapsulate the state used by AEM components into objects – commonly referred to as models – which can then be used while rendering the response. For example, the Sling Modelsframework is a great way to do this. If the Sightly format is used for your template, you can only use very simple presentation logic, meaning you must use a model class to do more complex operations.

One of the many benefits of this approach is that your model classes can be automatically tested as part of a continuous integration (CI) set-up. When using Java models, a common approach is to use unit tests to do this, and rely on 
Mockito or similar frameworks to simulate the behaviour of the AEM environment. Within such a rich environment, however, the test code quickly becomes hard to follow, as most of it is setting up the AEM simulation. Worse still, it’s very easy to get the simulation wrong, meaning your tests pass but your code is actually buggy.

AEM Context JUnit Rule

The AEM mock context can be injected into a JUnit test using a custom JUnit rule named AemContext. This rules takes care of all initialization and cleanup tasks required to make sure all unit tests can run independently (and in parallel, if required).
public class ExampleTest {

  public final AemContext context = new AemContext();

  public void testSomething() {
    Resource resource = context.resourceResolver().getResource("/content/sample/en");
    Page page = resource.adaptTo(Page.class);
    // further testing


Personalization in AEM

Personalization: Personalization is a technique to serve personalized content to each user. It can be based on user logged in by city, country
Here are the steps involved in implementing personalization.

Step1: Create the Segments.(Segments hold the rule to be checked while displaying a teaser on any page)

Go to Tootls > Segmentation

Double click on created segment and configure the test condition to be evaluated. For eg: We are going to display the teaser for ‘Male’ users.

For this, drag the ‘User properties’ from side kick.