Friday, April 5, 2019

How to disable the minification for client libraries in Adobe Experience Manager(AEM)

How to disable the minification for client libraries in Adobe Experience Manager(AEM)


Minification refers to the process of removing unnecessary or redundant data without affecting how the resource is processed by the browser - e.g. code comments and formatting, removing unused code, using shorter variable and function names, and so on.

Minfication helps to reduce the size of the resources(Java Script and CSS) and improves the performance of page loading.

Sometimes we may required to disable the minifcation for specific Java script files may be due to the files are already minified or the issue with minification process.

Adobe Granite HTML Library Manager:


Un-select minify option in Adobe Granite HTML Library Manager through configMgr(http://localhost:4502/system/console/configMgr/com.adobe.granite.ui.clientlibs.impl.HtmlLibraryManagerImpl)

disable-minification-clientlibrary-aem

Please note this is a global configuration and it will impact all the client libraries, non of the client libraries will be minified now and this will impact the performance. This approach is not recommended as this will disable the minification for all the client libraries.

Disable Minfication for specific client libraries:


Enable the minification in global configuration(Adobe Granite HTML Library Manager) - http://localhost:4502/system/console/configMgr/com.adobe.granite.ui.clientlibs.impl.HtmlLibraryManagerImpl and disable the minification for required client libraries in client library level. This will only disable the minification for specific client library.

disable-minification-clientlibrary-aem


To disable the minification for specific client library add the below properties to client library node.

To disable Java Script Minification - add jsProcessor String[] default:none, min:none

disable-minification-clientlibrary-aem2.png

Please note jsProcessor String[] default:none was disabling the minification for Java Scripts in AEM 6.2 but the same is not working in AEM 6.4(min:none should be added as additional configuration)

To disable CSS Minification - add cssProcessor String[] default:none, min:none

disable-minification-clientlibrary-aem

Please note cssProcessor String[] default:none was disabling the minification for CSS in AEM 6.2 but the same is not working in AEM 6.4(min:none should be added as additional configuration)


Thursday, April 4, 2019

Issue with turning off location tracker feature(Remove the geolocation store) in Adobe Experience Manager(AEM)

Issue with turning off location tracker feature(Remove the geolocation store) in Adobe Experience Manager(AEM)


I was trying to turn off the location tracker in AEM 6.4, unfortunately it was not working.

Steps Followed:


  • Define new clientcontex- /etc/clientcontext/new (copy the existing /etc/clientcontext/default node through CRXDE)
geo-location-tracker-aem

geo-location-tracker-aem

  • Remove the geolocation store from /etc/clientcontext/new
geo-location-tracker-aem

geo-location-tracker-aem

  • Change the clientcontext path in Design mode of a page.
geo-location-tracker-aem

  • Replicate the design(e.g /etc/designs/default) to publisher


Unfortunately after implementing above steps still the geo location tracker popup was displaying in the browser.

The popup is displayed due to the clientcontext path is still pointing to the default path - /etc/clientcontext/default(Geo Location store is available) instead of pointing to /etc/clientcontext/new(Geo Location store is not available)

 $CQ(function() {
        CQ_Analytics.SegmentMgr.loadSegments("\/etc\/segmentation");
        CQ_Analytics.ClientContextUtils.init("\/etc\/clientcontext\/default", "\/content\/sample\/test");        
    });

Based on the analysis the root cause of the problem is currentStyle.getPath() inside the clientcontext component was returning the wrong path value.

 currentStyle.getPath() was returning /etc/designs/default/jcr:content/homepage but the expected value is /etc/designs/default/jcr:content/homepage/clientcontext(this node has the property path with the value /etc/clientcontext/new) due to the wrong  currentStyle.getPath() is returned server was not able to locate the path property and used the default clientcontext value-/etc/clientcontext/default

 The design path was modified by the below code executed before including the client context - 

if (!getWcmMode().isEdit() && !getWcmMode().isDesign()) {
IncludeOptions.getOptions(getRequest(), true).forceSameContext(true);
getRequest().setAttribute(ComponentContext.BYPASS_COMPONENT_HANDLING_ON_INCLUDE_ATTRIBUTE, false);
}

 <div data-sly-resource="${@path='clientcontext', resourceType='cq/personalization/components/clientcontext'}"></div>

The issue is resolved after changing the order of the above code blocks(this order should be maintained even if these two code blocks are in two different files).

<div data-sly-resource="${@path='clientcontext', resourceType='cq/personalization/components/clientcontext'}"></div>

if (!getWcmMode().isEdit() && !getWcmMode().isDesign()) {
IncludeOptions.getOptions(getRequest(), true).forceSameContext(true);
getRequest().setAttribute(ComponentContext.BYPASS_COMPONENT_HANDLING_ON_INCLUDE_ATTRIBUTE, false);
}

Now the /etc/clientcontext/new is considered and also the geolocation tracker popup is disabled.

 $CQ(function() {
        CQ_Analytics.SegmentMgr.loadSegments("\/etc\/segmentation");
        CQ_Analytics.ClientContextUtils.init("\/etc\/clientcontext\/new", "\/content\/sample\/test");        
    });


Tuesday, April 2, 2019

Exception while browsing the tags in page creation wizard: The method transform(Object) of type new Transformer(){} must override a superclass method - AEM

Exception while browsing the tags in page creation: The method transform(Object) of type new Transformer(){} must override a superclass method - AEM 


We were getting the following exception while browsing the tags in page creation wizard - http://localhost:4502/mnt/overlay/cq/gui/content/coral/common/form/tagfield/picker.html?root=%2fetc%2ftags&selectionCount=multiple&_=1554223439347 500 (Server Error)

tag_browsing_issue_500_error

tag_browsing_issue_500_error

tag_browsing_issue_500_error

The below exception is displayed while trying to open the above mentioned URL

Compilation errors in /libs/cq/gui/components/coral/common/form/tagfield/datasources/children/children.java: Line 78, column 3367 : The method transform(Object) of type new Transformer(){} must override a superclass method
Cannot serve request to /mnt/overlay/cq/gui/content/coral/common/form/tagfield/picker.html in /libs/cq/gui/components/coral/common/form/tagfield/datasources/children/children.java

Exception:
org.apache.sling.scripting.java.impl.ServletWrapper$CompilerException: Compilation errors in /libs/cq/gui/components/coral/common/form/tagfield/datasources/children/children.java:
Line 78, column 3367 : The method transform(Object) of type new Transformer(){} must override a superclass method

tag_browsing_issue_500_error

Steps to resolve the issues:


Clear the compiled JSP cache:


The compiled jsp class files might have corrupted, follow the below steps to remove the existing classes and recompile the JSP's

Go to http://aem-host:port/system/console/slingjsp
Click Recompile all JSPs.

Unfortunately the specified issue was not resolved after clearing the cache.

Verify the Source VM and Target VM in Apache Sling Java Script Handler:


Ensure the the Source VM and Target VM values are specified with the version the AEM server is running or specify as auto to automatically consider the current VM version.

In our case the VM version was pointing to 1.5 but our current VM version is 1.8, the issue was resolved after changing the VM versions to auto.

This issue was observed in AEM 6.4 version after upgrading from AEM 6.2, the same VM version(1.5) was working in AEM 6.2 without any issue.

tag_browsing_issue_500_error

tag_browsing_issue_500_error




Wednesday, March 6, 2019

How to get the currentPage URL in cq:dialog dropdown datasources?

How to get the currentPage URL in cq:dialog dropdown datasources?

In Touch UI dialog's, the dynamic dropdownlist are loaded through data sources, sometime we may need to get the current page URL from where the dialog is opened to load the dropdownlist data.

String path= request.getParameter("item");

Returns the content path with out jcr:content, e.g /content/test/en/home

String path = (String) request.getAttribute(com.adobe.granite.ui.components.Value.CONTENTPATH_ATTRIBUTE);

Returns the path with jcr:content, e.g /content/test/en/home/jcr:content


import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.LinkedHashMap;

import javax.servlet.Servlet;
import javax.servlet.ServletException;

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.apache.felix.scr.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.felix.scr.annotations.Service;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;


import org.apache.sling.api.wrappers.ValueMapDecorator;
import com.adobe.granite.ui.components.ds.DataSource;
import com.adobe.granite.ui.components.ds.SimpleDataSource;
import com.adobe.granite.ui.components.ds.ValueMapResource;


import com.adobe.granite.ui.components.Value;
import org.apache.sling.api.resource.ResourceMetadata;;

@Service(value = Servlet.class)
@Component(metatype = true)
@Properties({
@Property(name = "sling.servlet.resourceTypes", value = "/services/availableCountryDataSource1"),
@Property(name = "service.description", value = "Get country list"),
@Property(name = "label", value = "countryList") })

public class AvailableCountryDataSource extends SlingSafeMethodsServlet {

@Reference
private ResourceResolverFactory resolverFactory;

private static final long serialVersionUID = 1180258251365536303L;

private static final Logger log = LoggerFactory.getLogger(AvailableCountryDataSource.class);
protected void doGet(SlingHttpServletRequest request,SlingHttpServletResponse response) throws ServletException,IOException {

final Map<String, String> countriesdata = new LinkedHashMap<String, String>();
Map<String, Object> param = new HashMap<String, Object>();
    param.put(ResourceResolverFactory.SUBSERVICE, "Albin");
    ResourceResolver resourceResolver=null;
try{

ArrayList<Resource> countryList = new ArrayList<Resource>();
ValueMap valueMap = new ValueMapDecorator(new HashMap<String, Object>());
ValueMap properties =null;

String resourcePath =(String)request.getAttribute(Value.CONTENTPATH_ATTRIBUTE);
resourceResolver = resolverFactory.getServiceResourceResolver(param);
Resource resource = resourceResolver.getResource(resourcePath);
properties=resource.adaptTo(ValueMap.class);

String data = properties.get("countryList", (String) null);

    if(data != null ){
log.error("INSIDE IF");
ValueMap vm =null;
for(String country : data.split(",")){

String[] tokens = country.split(";");
if(tokens == null || tokens.length != 2){
continue;
}
vm = new ValueMapDecorator(new HashMap<String, Object>());
vm.put("value", tokens[0] );
vm.put("text",  tokens[1]);

countryList.add(new ValueMapResource(request.getResourceResolver(),new ResourceMetadata(), "nt:unstructured", vm));
}

}
DataSource dataSource = new SimpleDataSource(countryList.iterator());
log.debug("dataSource...");
request.setAttribute(DataSource.class.getName(), dataSource);

}catch(Exception e){
log.error("Error while retrieving countries.",e);
}
finally{
if(resourceResolver!=null){
resourceResolver.close();
  }
}

    }
}
cq-dialog-dropdown-datasource



Wednesday, February 27, 2019

Adobe Experience Manager(AEM) 6.4 - Touch UI conversion Tips

Adobe Experience Manager(AEM) 6.4 - Touch UI conversion Tips

This post explains some of the issues identified during Touch UI conversion in AEM 6.4.

Embedded child components are not editable in Touch UI:


The Touch UI editing is not enabled for the components embedded in another component

e.g

The component2 is embedded in component 1(component1.html)

 <div data-sly-resource ="${ @path='component2', resourceType='/apps/test/components/component2 '}" >

The edit option is enabled for parent component(componet1) but not for child component(component2)

editing_issue_embedded_components

The embedded component editing is not enabled if the parent component also included the parsys through sly tag.

The issue is resolved after replacing the sly tag with div tag

<sly  data-sly-resource ="${ @path='cartBottomParsys', resourceType='wcm/foundation/components/parsys'}"/>

to

<div data-sly-resource ="${ @path='cartBottomParsys', resourceType='wcm/foundation/components/parsys'}"/>

editing_issue_embedded_components

cq:dialog Inheritence:


Parent dialog tabs and properties are displayed(Inherited) in the child component  in Touch UI but the same is not inherited in classic UI.

To hide the parent dialog tabs and properties in child components add the below property to the items node under tabs node in child component - e.g /apps/test/components/pages/homepage/cq:dialog/content/items

Name: sling:hideChildren
Type: String[]
Value: *

To hide the specific tabs from parent component

Name: sling:hideChildren
Type: String[]
Value: tab1,tab2

hide_cq_dialog_tabs.png

Hide/show tabs in Coral 3 UI dialog