Friday, 10 March 2017

Get the rendered HTML for an AEM resource, component or page

It's easy to retrieve a rendered component by making a GET request. Apache Sling's SlingMainServlet and DefaultGetServletwill process GET requests, take the path's extension into account, and return the rendered resource. The most obvious example of triggering this process is simply typing the component's path into the browser's address bar or making an AJAX call. You can retrieve the HTML markup (or JSON, XML, txt, PDF, etc...) for a component as well as a page if you provide the correct path. After all, they're both just Sling resources. 

Trying to get the rendered HTML of a component on the server side is still easy, but requires a little more work. Without knowing the inner workings of Sling, you might use Java's java.net.HttpUrlConnection class to construct and make an HTTP request from within your application to your application.

The better way is to use the SlingRequestProcessor service as the entry point into Sling's process. The processRequest method of the SlingRequestProcessor takes an HttpServletRequest, HttpServletResponse, and Resource Resolver as parameters. The only trick is that you need to provide a request that enables you to set the request path and a response that enables you to get the OutputStream as a String.

AEM provides the RequestResponseFactory where you can easily get such a request and response.

Using Granite DataSource objects to populate Experience Manager 6.2 Touch UI Select objects

You can create an Adobe Experience Manager (AEM) 6.2 Touch UI component that contains a drop-down control that can be used within the AEM Touch UI view. An AEM author selects drop-down values during design time. For example, an author can select a USA state value from an AEM component that displays address information. A drop-down control is populated by using a com.adobe.granite.ui.components.ds.DataSource object. For information, see DataSource.
Once you create a DataSource object, its data can be used to dynamically populate a drop-down control, as shown in this illustration.

A drop-down control populated by using a DataSouce object

Monday, 6 March 2017

Programmatically manipulating Touch UI Fields

When developing Adobe Experience Manager custom components, you can programmatically interact with fields located in a Touch UI component dialog using an API. That is, you can control the behaviour of a field (such as a checkbox) by using application logic. For example assume that you have a checkbox located within a component dialog and you want to have the ability to check a condition and then dynamically check or uncheck the checkbox (this is shown later in this article).
Using JavaScript application logic, you can dynamically check the box so that the checkbox appears checked when an AEM author opens the dialog box, as shown in this illustration. 

Saturday, 4 March 2017

Things to know about AEM Touch UI

Adobe introduced a new touch-optimized UI with AEM 5.6 for the author environment. This differs considerably from the original classic UI as it is designed to operate on both touch and desktop devices. The basic principles of the touch-optimized UI are:
  • Mobile first (with desktop in mind)
  • Responsive design
  • Context relevant display
  • Reusable
  • Include embedded reference documentation
  • Include embedded tests
  • Bottom-up design to ensure these principles are applied to every element and component

Display dynamic popup using GTM

There are different ways to display a dynamic modal popup, one of the best way is displaying the modal popup using google tag manager, as there will not be any code required. All changes to be done in GTM console. 


Dynamic modal using GTM
Dynamic modal using GTM

Touch UI (Rich Text) Overlay Component does not work when included statically on the template

<div data-sly-resource="${ @path='richText' , resourceType='/apps/XXX/components/content/text'}" ></div>
Included Statically on a Template.  When Tries to Edit the dialog : 
I see error in console 
GET http://localhost:4502/content/a/b/c/jcr:content/richText.json?_=1458055488719 404 (Not Found)

But when I drop the component statically on a template it works fine. 
This is because when you include it that way, the "text" resource is technically null and not available.  Since you're including it in your page component, modify the associated template and pre-set the text node.  Example:
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
          jcr:description="Page Template"
          jcr:primaryType="cq:Template"
          jcr:title="Page Template"
          allowedPaths="[/content/site/en(/.*)?]"
          ranking="{Long}100">
    <jcr:content
            jcr:primaryType="cq:PageContent"
            sling:resourceType="site/components/page/interior"
            cq:designPath="/etc/designs/site">
            <text jcr:primaryType="nt:unstructured" sling:resourceType="wcm/foundation/components/text" />
    </jcr:content>
</jcr:root>