Tuesday, February 12, 2019

The Servlet status is disabled in AEM(Adobe Experience Manager) 6.4

The Servlet status is disabled in AEM(Adobe Experience Manager) 6.4


The Servlet created with Archetype 10 is disabled while deploying the same to AEM 6.4(the same is applicable for the Servlet developed in AEM 6.4 with OSGI annotation)

servlet-disabled-aem-6.4

servlet-disabled-aem-6.4

servlet-disabled-aem-6.4

The servlet code(enabled with scr annotation)

package config.core.servlets;

import java.io.IOException;
import java.util.*;
import javax.servlet.*;

import org.apache.sling.api.*;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.servlets.*;
import org.osgi.framework.Constants;
import org.apache.sling.commons.json.*;

import org.apache.felix.scr.annotations.*;
import org.apache.felix.scr.annotations.sling.SlingServlet;
import org.apache.felix.scr.annotations.ConfigurationPolicy;

@Service
@Component(policy = ConfigurationPolicy.REQUIRE)
@SlingServlet(paths = "/bin/servlet/selector1", selectors = "dynamicpopulate",
    extensions = "json", methods = "GET", generateComponent = false, generateService = false)

public class FirstServletSelector1 extends SlingAllMethodsServlet {

    protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
    throws ServletException, IOException {
        JSONArray jsonArray = new JSONArray();
        JSONObject jsonObject = new JSONObject();
        JSONObject jsonObject1 = new JSONObject();
        JSONObject jsonObject2 = new JSONObject();

        try {

            jsonObject.put("value", "1");
            jsonObject.put("text", "Albin1");
            jsonObject1.put("value", "2");
            jsonObject1.put("text", "Albin2");
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


        jsonArray.put(jsonObject1);
        jsonArray.put(jsonObject);
        response.getWriter().write(jsonArray.toString());
    }

}

The issue is ConfigurationPolicy is defined as REQUIRE but there is no sling:OsgiConfig defined in the repository for the servlet PID.

When we make component 'policy' to 'REQUIRE', OSGi container expects corresponding configuration object (osgi:Config node) to become satisfied

The issue can be resolved either one of the below approach
  • Change the ConfigurationPolicy.REQUIRE to ConfigurationPolicy.OPTIONAL in case the sling:OsgiConfig is not mandatory to enable this servlet
  • Enable the sling:OsgiConfig in the repository with required configuration values for this servlet



The servlet is in Active state after following one of the above approach.




The details mentioned in this post is one of the reason to mark the Servlet status as disabled.


Monday, February 4, 2019

how to hide/show tabs in Coral 3 UI dialog - Adobe Experience Manager(AEM)

how to hide/show tabs in Coral 3 UI dialog - Adobe Experience Manager(AEM)

This post will explain the approach to enable and disable the tabs in Coral 3 UI dialog.

Define the Coral UI 3 Touch UI dialog (cq:dialog)with require fields

The XML structure of the dialog is below

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:granite="http://www.adobe.com/jcr/granite/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
    jcr:primaryType="nt:unstructured"
    jcr:title="Column Component Responsive"
    sling:resourceType="cq/gui/components/authoring/dialog"
    extraClientlibs="[dialogevent]">
    <content
        granite:class="tabtest"
        jcr:primaryType="nt:unstructured"
        sling:resourceType="granite/ui/components/coral/foundation/tabs">
        <items jcr:primaryType="nt:unstructured">
            <presets
                jcr:primaryType="nt:unstructured"
                jcr:title="Presets"
                sling:resourceType="granite/ui/components/coral/foundation/fixedcolumns" >
                <items jcr:primaryType="nt:unstructured">
                    <column
                        jcr:primaryType="nt:unstructured"
                        sling:resourceType="granite/ui/components/foundation/container">
                        <items jcr:primaryType="nt:unstructured">
                            <title
                                jcr:primaryType="nt:unstructured"
                                sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
                                fieldDescription="Note: Titles are not available on the Advanced preset"
                                fieldLabel="Add Title to Columns?"
                                name="./title"
                                text="Add Title to Columns?"/>
                            <padding
                                jcr:primaryType="nt:unstructured"
                                sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
                                fieldDescription="check to remove padding from columns"
                                fieldLabel="Remove Padding from Columns?"
                                name="./removePadding"
                                text="Remove Padding from Columns?"/>
                            <presets
                                granite:class="presets"
                                jcr:primaryType="nt:unstructured"
                                sling:resourceType="granite/ui/components/coral/foundation/form/select"
                                fieldDescription="Choose Column style(Advanced for column customization)."
                                fieldLabel="Presets"
                                name="./presets">
                                <items jcr:primaryType="nt:unstructured">
                                    <option1
                                        jcr:primaryType="nt:unstructured"
                                        text="2 Column(50%,50%) No Offset"
                                        value="50-50-no-offset"/>
                                    <option2
                                        jcr:primaryType="nt:unstructured"
                                        text="2 Column(50%,50%) with Offset"
                                        value="50-50-with-offset"/>
                                </items>
                            </presets>
                        </items>
                    </column>
                </items>
            </presets>
            <col1
                jcr:primaryType="nt:unstructured"
                jcr:title="Column 1"
                sling:resourceType="granite/ui/components/coral/foundation/fixedcolumns">
                <items jcr:primaryType="nt:unstructured">
                    <column
                        jcr:primaryType="nt:unstructured"
                        sling:resourceType="granite/ui/components/foundation/container">
                        <items jcr:primaryType="nt:unstructured">
                            <mobiledialog
                                jcr:primaryType="nt:unstructured"
                                jcr:title="Mobile Break Point"
                                sling:resourceType="granite/ui/components/coral/foundation/form/fieldset">
                                <items jcr:primaryType="nt:unstructured">
                                    <visible
                                        jcr:primaryType="nt:unstructured"
                                        sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
                                        fieldDescription="Check to hide on this device."
                                        fieldLabel="Hidden?"
                                        name="./col1/mobile/hidden"
                                        text="Hidden?"/>
                                </items>
                            </mobiledialog>
                        </items>
                    </column>
                </items>
            </col1>
            <col2
                jcr:primaryType="nt:unstructured"
                jcr:title="Column 2"
                sling:resourceType="granite/ui/components/coral/foundation/fixedcolumns">
                <items jcr:primaryType="nt:unstructured">
                    <column
                        jcr:primaryType="nt:unstructured"
                        sling:resourceType="granite/ui/components/foundation/container">
                        <items jcr:primaryType="nt:unstructured">
                            <mobiledialog
                                jcr:primaryType="nt:unstructured"
                                jcr:title="Mobile Break Point"
                                sling:resourceType="granite/ui/components/coral/foundation/form/fieldset">
                                <items jcr:primaryType="nt:unstructured">
                                    <visible
                                        jcr:primaryType="nt:unstructured"
                                        sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
                                        fieldDescription="Check to hide on this device."
                                        fieldLabel="Hidden?"
                                        name="./col2/mobile/hidden"
                                        text="Hidden?"/>
                                </items>
                            </mobiledialog>
                        </items>
                    </column>
                </items>
            </col2>
            <col3
                jcr:primaryType="nt:unstructured"
                jcr:title="Column 3"
                sling:resourceType="granite/ui/components/coral/foundation/fixedcolumns">
                <items jcr:primaryType="nt:unstructured">
                    <column
                        jcr:primaryType="nt:unstructured"
                        sling:resourceType="granite/ui/components/foundation/container">
                        <items jcr:primaryType="nt:unstructured">
                            <mobiledialog
                                jcr:primaryType="nt:unstructured"
                                jcr:title="Mobile Break Point"
                                sling:resourceType="granite/ui/components/coral/foundation/form/fieldset">
                                <items jcr:primaryType="nt:unstructured">
                                    <visible
                                        jcr:primaryType="nt:unstructured"
                                        sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
                                        fieldDescription="Check to hide on this device."
                                        fieldLabel="Hidden?"
                                        name="./col3/mobile/hidden"
                                        text="Hidden?"/>
                                </items>
                            </mobiledialog>
                        </items>
                    </column>
                </items>
            </col3>
            <col4
                granite:hide="{Boolean}true"
                jcr:primaryType="nt:unstructured"
                jcr:title="Column 4"
                sling:resourceType="granite/ui/components/coral/foundation/fixedcolumns">
                <items jcr:primaryType="nt:unstructured">
                    <column
                        jcr:primaryType="nt:unstructured"
                        sling:resourceType="granite/ui/components/foundation/container">
                        <items jcr:primaryType="nt:unstructured">
                            <mobiledialog
                                jcr:primaryType="nt:unstructured"
                                jcr:title="Mobile Break Point"
                                sling:resourceType="granite/ui/components/coral/foundation/form/fieldset">
                                <items jcr:primaryType="nt:unstructured">
                                    <visible
                                        jcr:primaryType="nt:unstructured"
                                        sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
                                        fieldDescription="Check to hide on this device."
                                        fieldLabel="Hidden?"
                                        name="./col4/mobile/hidden"
                                        text="Hidden?"/>
                                </items>
                            </mobiledialog>
                        </items>
                    </column>
                </items>
            </col4>
        </items>
    </content>
</jcr:root>

Add the granite:class property with unique class name(tabtest) for the tab, also add a unique class name(presets) to the drop down list to handle the change event.

coral_ui3_enable_disable_tabs


Defining the Event Listener:


Define a cq:ClientLibraryFolder node under the component, name it clientlibs and add the following properties.

categories (String[]) - <define category name> e.g dialogevent
Create js.txt and event.js under clientlibs folder.
Add below lines into js.txt

#base=js
event.js


Add the below script in event.js

This script hide the second tab on dialog load and shows the second tab on the change event of the drop down  with class name .presets

(function (document, $, Coral) {

  var $doc = $(document);

 $doc.on('foundation-contentloaded', function(e) { 

  var coralTab = $(".tabtest coral-tablist coral-tab");
    coralTab[1].hide();

     console.log(coralTab[1].get);

$('.presets', e.target).each(function (i, element) {

            Coral.commons.ready(element, function (component) {

                $(component).on("change",function (event) {

                     var coralTab = $(".tabtest coral-tablist coral-tab");
                     coralTab[1].show();

                });
            });
        });
  });
})(document, Granite.$, Coral);

Add the below property in cq:dialog node

extraClientlibs String[] - dialogevent (the client library defined in the previous step)

coral_ui3_enable_disable_tabs


Second tab(Column 1 is hided on dialog load)

coral_ui3_enable_disable_tabs
Second tab(Column 1) is shown on the drop down change event.

coral_ui3_enable_disable_tabs



The granite:hidden property can be added to the dialog properties to hide the tab but the hidden tab will not be able to un-hide from script as the hided tab will not be loaded to the browser.

coral_ui3_enable_disable_tabs

coral_ui3_enable_disable_tabs
This component is tested in AEM 6.4



Saturday, February 2, 2019

How to handle the Coral UI 3 Select(Drop down) change event in Touch UI dialogs?

How to handle the Coral UI 3 Select(Drop down) change even in Touch UI dialog?

This post will explain the details on how to handle the change event of Coral UI 3 Select(Drop down) in Touch UI dialog's

Define the Coral UI 3 Touch UI dialog (cq:dialog)with require fields

The XML structure of the dialog is below

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:granite="http://www.adobe.com/jcr/granite/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
    jcr:primaryType="nt:unstructured"
    jcr:title="Column Component Responsive"
    sling:resourceType="cq/gui/components/authoring/dialog"
    extraClientlibs="[dialogevent]">
    <content
        jcr:primaryType="nt:unstructured"
        sling:resourceType="granite/ui/components/coral/foundation/tabs">
        <items jcr:primaryType="nt:unstructured">
            <presets
                jcr:primaryType="nt:unstructured"
                jcr:title="Presets"
                sling:resourceType="granite/ui/components/coral/foundation/fixedcolumns">
                <items jcr:primaryType="nt:unstructured">
                    <column
                        jcr:primaryType="nt:unstructured"
                        sling:resourceType="granite/ui/components/foundation/container">
                        <items jcr:primaryType="nt:unstructured">
                            <title
                                granite:class="title"
                                jcr:primaryType="nt:unstructured"
                                sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
                                fieldDescription="Note: Titles are not available on the Advanced preset"
                                fieldLabel="Add Title to Columns?"
                                name="./title"
                                text="Add Title to Columns?"/>
                            <padding
                                jcr:primaryType="nt:unstructured"
                                sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
                                fieldDescription="check to remove padding from columns"
                                fieldLabel="Remove Padding from Columns?"
                                name="./removePadding"
                                text="Remove Padding from Columns?"/>
                            <presets
                                granite:class="presets"
                                jcr:primaryType="nt:unstructured"
                                sling:resourceType="granite/ui/components/coral/foundation/form/select"
                                fieldDescription="Choose Column style(Advanced for column customization)."
                                fieldLabel="Presets"
                                name="./presets">
                                <items jcr:primaryType="nt:unstructured">
                                    <option1
                                        jcr:primaryType="nt:unstructured"
                                        text="2 Column(50%,50%) No Offset"
                                        value="50-50-no-offset"/>
                                    <option2
                                        jcr:primaryType="nt:unstructured"
                                        text="2 Column(50%,50%) with Offset"
                                        value="50-50-with-offset"/>
                                    <option3
                                        jcr:primaryType="nt:unstructured"
                                        text="2 Column(60%,40%)"
                                        value="60-40"/>                                 
                                    <option10
                                        jcr:primaryType="nt:unstructured"
                                        text="Advanced"
                                        value="Advanced"/>
                                </items>
                            </presets>
                            <colnums
                                granite:class="columns"
                                jcr:primaryType="nt:unstructured"
                                sling:resourceType="granite/ui/components/coral/foundation/form/select"
                                fieldDescription="Choose the number of column(s) will be created."
                                fieldLabel="Columns"
                                name="./columns">
                                <items jcr:primaryType="nt:unstructured">
                                    <_x0031_
                                        jcr:primaryType="nt:unstructured"
                                        text="1"
                                        value="1"/>
                                    <_x0032_
                                        jcr:primaryType="nt:unstructured"
                                        text="2"
                                        value="2"/>                                 
                                </items>
                            </colnums>
                        </items>
                    </column>
                </items>
            </presets>
        </items>
    </content>
</jcr:root>


Defining the Event Listener:


Add the granite:class property with unique class name in all the required fields that should be processed in the event listener.

coral_ui3_select_change_listener

Define a cq:ClientLibraryFolder node under the component, name it clientlibs and add the following properties.

categories (String[]) - <define category name> e.g dialogevent
Create js.txt and event.js under clientlibs folder.
Add below lines into js.txt

#base=js
event.js

coral_ui3_select_change_listener


Add the below script in event.js

This script hide drop down with class .columns on dialog load
Register a change event on the drop down  with class name .presets

On-change of the value in the drop down with class name .presets and if the selected value is 'Advanced' then un-hide the drop down with class .columns and also select the checkbox with class name .title

If the value is other than 'Advanced' then hide drop down with class .columns and un-select the checkbox with class name .title


(function (document, $, Coral) {

  var $doc = $(document);

 $doc.on('foundation-contentloaded', function(e) {

  $('.columns').parent().addClass("hide"); 

$('.presets', e.target).each(function (i, element) {

            Coral.commons.ready(element, function (component) {

                $(component).on("change",function (event) {

                  if(component.value=='Advanced')
                  {
                  $('.columns').parent().removeClass("hide");
                        $('.title').prop('checked', true);
                  }else
                  {
$('.columns').parent().addClass("hide");
                        $('.title').prop('checked', false);
                  }
                });
            });
        });
  });

Add the below property in cq:dialog node

extraClientlibs String[] - dialogevent (the client library defined in the previous step)

coral_ui3_select_change_listener

Now add the component to a page and author it

coral_ui3_select_change_listener
coral_ui3_select_change_listener



Friday, February 1, 2019

/etc/cloudsettings/default/contexthub.kernel.js is not loading in Adobe Experience Manager(AEM) 6.4

/etc/cloudsettings/default/contexthub.kernel.js is not loading in Adobe Experience Manager(AEM) 6.4

The /etc/cloudsettings/default/contexthub.kernel.js(The ContextHub library) is not loading upgrading the AEM environment to 6.4 version.

The below exception is thrown in the error log

01.02.2019 21:05:44.636 *ERROR* [10.153.113.29 [1549055144628] GET /etc/cloudsettings/default/contexthub.kernel.js HTTP/1.1] org.apache.sling.servlets.resolver.internal.SlingServletResolver Original error null

The issue is resolved after changing the value of sling:resourceType from /libs/granite/contexthub/cloudsettings/components/baseconfiguration  to granite/contexthub/cloudsettings/components/baseconfiguration in /etc/cloudsettings/default/contexthub

contexthub_kernel_js_notloading


contexthub_kernel_js_notloading

Refer https://forums.adobe.com/message/10907246 for additional details