AEM · AEM 6

AEM | ACS – Generic List | Dialog Configuration – Classic UI


This article will explain how to identify and retrieve values from a list for current site, which is configured in Classic UI dialog’s dropdown.

Note:

  1. Please see Generic List – Support Site Inheritance for understanding of Generic List requirement and complete solution.
  2. For Touch UI, Please see Generic List | Dialog Configuration – Touch UI

Classic UI dialog’s dropdown support JSON as input which can be generated by servlet. We will also create a servlet to support generic list in Classic UI.

  1. Create Generic List Servlet: This servlet will use MyList Service to find and fetch correct list. This servlet will be invoked with selector “mylist” and extn “json”. (eg. /content/mysite/page/node.mylist.json). Click here to download code.
    package com.mysite.servlets;
    
    import java.io.IOException;
    import javax.servlet.ServletException;
    
    import org.apache.felix.scr.annotations.Reference;
    import org.apache.felix.scr.annotations.sling.SlingServlet;
    import org.apache.sling.api.SlingHttpServletRequest;
    import org.apache.sling.api.SlingHttpServletResponse;
    import org.apache.sling.api.servlets.SlingAllMethodsServlet;
    
    import com.mysite.services.MyList;
    import org.apache.sling.commons.json.JSONArray;
    
    /**
     * Generic List Servlet to return list based on requested site context
     * 
     * @author Mohit K. Bansal
     */
    
    @SlingServlet(
        resourceTypes = {"sling/servlet/default"},
        methods = {"GET"},
        selectors = {"mylist"},
        extensions = {"json"}
    )
    public class GenericListServlet extends SlingAllMethodsServlet {
    	
        private static final long serialVersionUID = 1L;
    
        @Reference
        MyList list;
        
        /**
         * Implementation for get request
         */
        protected void doGet(final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws ServletException, IOException {
        	try {
        	    /**
        	     * Get List in JSON fromat using MyList Service
        	     */
        	    JSONArray jarray = list.getJSONList(request);
        		
        	    response.getWriter().write(jarray.toString());
        	} catch (IOException ioException) {
        	}
        }
    }
    
  2. Update dialog to invoke mylist servlet
    <jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
        jcr:primaryType="cq:Widget"
        fieldLabel="Target"
        name="./target"
        options="$PATH/<list-name>.mylist.json"
        type="select"
        xtype="selection"/>
Advertisements

2 thoughts on “AEM | ACS – Generic List | Dialog Configuration – Classic UI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s