Friday, 17 February 2017

Spring Editons of Ask the AEM Community Experts

Hello AEM Community. I wanted to let you know that we have lined up some very awesome sessions of Ask the AEM Community Experts for you:


  • In March we will focus on AEM and Analytics and how to work with these two products in AEM 6.2.
  • In April - we will do Responsive Layout with Lokesh. 

This is your chance to attend and ask the community experts questions related to these subjects and see the use cases in action.

To watch the March Session, click: 

http://bit.ly/ATACE3282107



Join the Adobe Experience Cloud Community 

Join the Adobe Experience Cloud Community by clicking this banner




I (Scott Macdonald) am a Senior Digital Marketing Community Manager at Adobe Systems with 20 years in the high tech industry. I am also a programmer with knowledge in Java, JavaScript, C#,C++, HTML, XML and ActionScript. If  you would like to see more CQ or other Adobe Digital Marketing end to end articles like this, then leave a comment and let me know what content you would like to see.


TwitterFollow the Digital Marketing Customer Care team on Twitter @AdobeExpCare.

YouTube: Subscribe to the AEM Community Channel



Wednesday, 15 February 2017

Creating a custom Experience Manager sling:resourceType for Touch UI

You can create a custom sling resource type that can be used in an Adobe Experience Manager (AEM) Touch UI component by using a JQuery plug-in. That is, if you want to define a field in a Touch UI component dialog that is not available with the available Granite API, you can define your own custom type. This is similiar to how you can define a custom xtype when working in the Classic UI. For information, see Creating your first Adobe Experience Manager custom xtype.

As an AEM developer working in the Touch UI, it is important to understand how to create a custom sling resource type to be able to define custom fields.  In the AEM community, there has been requests on how to develop a full color spectrum field for a Touch UI component dialog, as shown in this illustration.


To successfully get this color picker in an AEM Touch UI dialog, specify a path that references the JQuery plugin as a value of the sling:resourceType property in CRXDE Lite, as shown here.  




Join the Adobe Experience Cloud Community 

Join the Adobe Experience Cloud Community by clicking this banner




I (Scott Macdonald) am a Senior Digital Marketing Community Manager at Adobe Systems with 20 years in the high tech industry. I am also a programmer with knowledge in Java, JavaScript, C#,C++, HTML, XML and ActionScript. If  you would like to see more CQ or other Adobe Digital Marketing end to end articles like this, then leave a comment and let me know what content you would like to see.


TwitterFollow the Digital Marketing Customer Care team on Twitter @AdobeExpCare.

YouTube: Subscribe to the AEM Community Channel


Tuesday, 7 February 2017

Creating an AEM HTL component that queries the JCR

You can create an Adobe Experience Manager (AEM) HTL (used to be known as Sightly) component that queries data located in the AEM Java Content Repository (JCR). To query data, you use an HTL Java class that extends the WCMUsePojo API and the javax.jcr.query.Query instance that belongs to the JCR Query API. This API supports both searching and querying operations. For example, assume that your AEM application tracks your organization’s customers. You can develop an AEM HTL component that is able to query the JCR to obtain a customer result set in which a digital marketer is interested.



Assume that you have customer data in the AEM JCR. 



Using an HTL component that extends WCMUsePojo, you can retrieve the JCR data and display it.



This development walks you through how to create an AEM HTL component that queries a result set from the JCR. To read this development article, click https://helpx.adobe.com/experience-manager/using/htl_jcr.html

Join the Adobe Experience Cloud Community 

Join the Adobe Experience Cloud Community by clicking this banner




I (Scott Macdonald) am a Senior Digital Marketing Community Manager at Adobe Systems with 20 years in the high tech industry. I am also a programmer with knowledge in Java, JavaScript, C#,C++, HTML, XML and ActionScript. If  you would like to see more CQ or other Adobe Digital Marketing end to end articles like this, then leave a comment and let me know what content you would like to see.


TwitterFollow the Digital Marketing Customer Care team on Twitter @AdobeExpCare.

YouTube: Subscribe to the AEM Community Channel

Saturday, 4 February 2017

Adobe Experience Manager FAQs and other Tips

This post captures FAQs, and other tips for AEM that AEM Developers will find useful. We will update this list on an on-going basis.


How can I add a FAVICON to an AEM Site


How can I create an OAK Index


Unlike Jackrabbit 2, Oak does not index content by default. Custom indexes need to be created when necessary, much like with traditional relational databases. If there is no index for a specific query, possibly many nodes will be traversed. The query may still work but probably be very slow. 

To avoid performance issues, you need to create an OAK index. See these resources for more information:

2. GEMS Session on OAK Index

How come I cannot use Design Mode for We Retail?


If you attempt to use Design Mode for We Retail in order to add new components, you will notice that Design mode is not there. 




The reason is pages based on Editable Templates do not have Design Mode. To add a component group, you need to add the component group by using the editable templates Policy. 




For information about working with Policies and editable templates - see this article - http://scottsdigitalcommunity.blogspot.ca/2017/04/creating-adobe-experience-manager.html

What are Projects in AEM? 

See this link  - Developing Projects in AEM.

How can I test my AEM Code? 
You can test your AEM Java code by using the Test class that is generated for you when you build an Adobe Maven 11 Archetype project. See http://scottsdigitalcommunity.blogspot.ca/2017/09/creating-adobe-experience-manager-63.html.

 For example, assume you create a project named AEM633. Once you build this project, you will have a class named TestHelloWorldModel located in this package: 

com.foo.core.models (under src\test\java)  

All of the POM dependencies are setup for you. Create a simple interface in the Core package named Foo

package com.foo.core;

public interface Foo {


public String getName(); 

}

Then create an implementation class that uses a @Component annotation in the same package. 

package com.foo.core;


import org.osgi.service.component.annotations.Component;

@Component
public class FooImpl implements Foo{

public String getName()
{
return "Scott" ; 
}


}


This is about the most basic AEM class that you can build. It has one method that returns a static value for the getName method. Now the question is how can we test this method? 

The answer is to use the TestHelloWorldModel class that already exists. You can create a Foo object and then test the getName method. See the bold code below. 



package com.foo.core.models;



import static org.junit.Assert.assertNotNull;

import static org.junit.Assert.assertTrue;

import static org.mockito.Mockito.mock;

import static org.mockito.Mockito.when;



import java.util.UUID;



import junitx.util.PrivateAccessor;


import org.apache.sling.settings.SlingSettingsService;
import org.junit.Before;
import org.junit.Test;

import com.foo.core.Foo;
import com.foo.core.FooImpl;



/**
 * Simple JUnit test verifying the HelloWorldModel
 */
public class TestHelloWorldModel {

    //@Inject
    private HelloWorldModel hello;
    
    private Foo myFoo;  
    
    private String slingId;
    
      
    @Before
    public void setup() throws Exception {
        SlingSettingsService settings = mock(SlingSettingsService.class);
        slingId = UUID.randomUUID().toString();
        when(settings.getSlingId()).thenReturn(slingId);

        hello = new HelloWorldModel();
        PrivateAccessor.setField(hello, "settings", settings);
        hello.init();
        
        myFoo = new FooImpl(); 
        
    }
    
    @Test
    public void testGetMessage() throws Exception {
        // some very basic junit tests
        String msg = hello.getMessage();
        assertNotNull(msg);
        assertTrue(msg.length() > 0);
      
      
    }
    
    @Test
    public void testFooMessage() throws Exception {
      
        //custom service
        String msgFoo = myFoo.getName() ; 
        assertNotNull(msgFoo);
        assertTrue(msgFoo.length() > 0);
    }

}

When you build the Maven project (for example, mvn clean install), you can see the Test results that are written to this file:

C:\AdobeCQ\AEM633\core\target\surefire-reports\com.foo.core.models.TestHelloWorldModel.txt



How can I disable the options in the Assets Toolbar? 


I have a requirement to remove options on the Assets toolbar. 



If you simply want to disable those, you can overlay:

/libs/dam/gui/content/assetdetails/jcr:content/actions

and add disabled (boolean) = true for these actions

How can I apply color to a Table in the RTE? 


This works as shown here: 

I need to create a QUIZ in AEM. Can I use AEM Forms?


You cannot use AEM Forms to create a quiz component. It's best to use a JQuery plugin and develop a custom component as discussed here: 



How can I configure AEM Link Checker to ignore certain URL patterns


See this community thread -- https://forums.adobe.com/thread/2422881

How do you display a DATE value in HTL? 

Assume you have a node named startDate, which is based on a Date data type. To display this value in HTL, you can use the following HTL syntax. 

${'yyyy-MM-dd HH:mm:ss.SSSXXX' @ format=head.startDate, timezone='UTC'}


How can I used GSON within AEM

To use the GSON XML library in AEM, you need to use the following dependency. 

 <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.8.0</version>

    </dependency>


How can I track Requests in AEM? 

You can use the "Recent requests" view in the web console ( /system/console/requests) to actually check what the request is internally doing. Every include and every forward is listed there and this should give you insight what's going on.

How can i align fields in a Touch UI Dialog? 


How can I use Sling Queries?

Core Project has dependency on javax.inject [0,1) Bundles and imports not getting deployed 
You can add

<!-- Import any version of javax.inject, to allow running on multiple versions of AEM -->
<Import-Package>javax.inject;version=0.0.0,*</Import-Package>

to your bundles pom.xml. This should solve your issue. This says take any version from the felix console for this bundle.  Add it under maven-scr-plugin 


How can I use an AEM API to find all Assets in a page?

How come when a Workflow is assigned to 1 user, sometimes another user can see it 

Assume you have two users:
  • User A
  • User B

Next, assume that you have a Workflow model that uses an OR Split and where the 1st step is assigned to User A.   See this model. 


Sometimes even if User A is assigned the a Workflow task- it may show up in User B inbox. This may happen if you have not specified User A as the 1st step. Also - it may happen if they Users are part of the workflow admin group.  In order for User B not to see a task assigned to another member, ensure that they both belong to the workflow-users group. 

Notice that User A is assigned a task when the workflow is started. Even if User B invokes the Workflow, a message is sent to User A - as shown here: 



Although User B invoked the Workflow, they do not get a message in their corresponding inbox. 




How can I get a reference to an AEM Service from a Sling Model

You cannot use @Reference to inject a service into a Sling Model. When attempting to get a service into an AEM Sling Model class - you can use @inject. See this thread:

https://forums.adobe.com/message/9864292#9864292

How can I limit the fields located in Multifield?

How can i change the Theme of a Touch UI Dialog? 

How can i modify the default text of a Parsys component? 
Where can I find good reference docs for Coral APIs

How do i use HTL syntax to include a Core Component in my static template?

You can use HTL syntax to include AEM Core components into a static template. For example, to include the List component into a template - specify this syntax: 

<div data-sly-resource="${'content' @ resourceType='core/wcm/components/list/v1/list'}">

Whats the difference between a static template and an editable template

In AEM 6.3 - I am getting osgi bundle whitelist error-osgi-service is NOT whitelisted to use SlingRepository.loginAdministrative 

You can either use a System user and the sling mapping service:
 http://scottsdigitalcommunity.blogspot.ca/2014/12/querying-adobe-experience-manager-6.html.

Or configure AEM - https://forums.adobe.com/thread/2355506

How can i integrate AEM with Hybris? 

In HTL, how can i add the parsys component?

Add this code:

<sly data-sly-resource="${'content-par' @ resourceType='wcm/foundation/components/parsys'}"/>


I can use both JCR API and SLing API to work with the AEM JCR. Which one is better? 


I want to send a message to a users AEM inbox? 


When working with Sling Models, can I reference grandchildren nodes and work with Collections? 

Yes, when you work with Sling Models, you can work with Grandchildren nodes from the node that you adapt. For example, consider the following JCR structure. 


Assume you adapt NodeCollections in your Sling Model: 

Resource resource = resourceResolver.getResource("/content/NodeCollections");

You can get the grandchildren nodes using this syntax and return them to  a Java LIST object. 

@Model(adaptables = Resource.class)
public class UserInfo {
   
@Inject 
private List<Resource> Dad;


    public List getGrandChildren()
    {
    return Dad ; 
    }
    

}

In this example, the List Object would contain six items.  See more here:

https://sling.apache.org/documentation/bundles/models.html

I want to know the difference between Sling Models and WCMUsePojo


Can Forms interact with Workflows? 


I want to know more information about OSGi Declarative Services Annotations in AEM


Whats the difference between Foundation components and Core components? 

See this community article for an answer:
http://adobeaemclub.com/aem63-core-components/

To learn to work with Core Components - see: 
https://helpx.adobe.com/experience-manager/using/aem63_components.html

A user does not have permission to modify Assets, can they execute a Workflow that modifies them? 

Any member of the workflow-users group can list and start workflows, irrespective of their permissions on the payload the selected to run the workflow.


Does AEM by default use J2EE Sessions and Cookies? 
Nothing in AEM uses JavaEE Sessions.  

Components cannot be moved. Why? 

If you want to move components upwards or downwards, you need to use copymove in cq:actions property.



Here it is!!



<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"

    cq:actions="[text:My Component,-,edit,delete,insert,copymove]"

    cq:dialogMode="floating"

    cq:layout="editbar"

    jcr:primaryType="cq:EditConfig">

</jcr:root>



I  am using AEM Forms, not AEM Sites
See these docs: https://helpx.adobe.com/aem-forms/6-1/help-tutorials.html


Can I use @Reference in an HTL Class that extends WCMUsePojo

You cannot use the @Reference annotation from a HTL class that extends WCMUsePojo. This can be used from a Java class that uses @Service to reference another service known as dependency injection. To learn about Dependency Injection in AEM, see this article: 


Now to learn how to get a referenece to another AEM service from a class that extends WCMUsePojo, see this article: 

Can I use @Reference  from within a Sling Servlet

You can use Dependency Injection from within a Sling Servlet. See this community article/video. 


Can I manipulate the Touch UI Rich Text Editor using code

See this community article - http://experience-aem.blogspot.ca/2015/01/aem-6-sp1-touch-ui-rich-text-editor-plugin-to-upper-case.html

How can I programmatically retrieve HTML from an AEM page

See this great community article by Nolle Yolles: http://www.nateyolles.com/blog/2015/10/get-rendered-html-for-an-aem-resource-or-component

What is cq.editconfig and when should i use it

Where do Lucene, Solr, ElasticSearch fit in the AEM Platform? 

Can i view an asset's metadata in CRXDE lite? 

Assume you have added metadata to a digital asset, as shown in this illustration. 


You can view the assets metadata by viewing a node named metadata under the asset in the AEM dam (/content/dam). For example, the above image is located here:

/content/dam/geometrixx-instore/cover-images/seasonal.jpg

The metadata is stored as node properties as shown in this illustration.


Can I programmatically work with Coral UI object such as checkboxes?

Yes you can. It involves creating a JS script in an AEM Clientlib and then coding. See the reference documentation here:


Given this setup in CRXDE Lite: 



You can get a reference to this checkbox object in a clientlibs folder. The name of the clientlibs folder for Touch UI dialogs is cq.authoring.dialog ( this is talked about here.  http://scottsdigitalcommunity.blogspot.ca/2015/05/using-event-handlers-in-adobe.html).

Code: 

(function ($, $document) {
    "use strict";

   

    $document.on("dialog-ready", function() {


        $('#kitten').attr('checked', true);     

        });


})(jQuery, jQuery(document));

The result is the checkbox is checked via code: 




Note - we are planning on conducting a full session of AEM Ask the Community Experts on AEM Developing with the Coral API. 

Need to search for special characters when searching JCR via JCR SQL2

Read this topic -- https://wiki.apache.org/jackrabbit/EncodingAndEscaping. YOU  need to escape illegal JCR characters.

How can i work with custom JARs that are not in the Maven repository

You can place the JAR in your local Maven Repository and then reference it in your POM file. For example, to resolve myCustomJAR_1.0.0.jar within an AEM service, the myCustomJAR_1.0.0.jar file must be located in the Maven repository. You can upload the myCustomJAR_1.0.0.jar to Maven by using this Maven command: 

mvn install:install-file -Dfile=C:/plugins/myCustomJAR_1.0.0.jar -DgroupId=com.foo.reports -DartifactId=jrurbersrt1.0 -Dversion=1.0 -Dpackaging=jar -DgeneratePom=true

Notice that you must specify the location of the myCustomJAR file in the -Dfile argument. Also notice that you specify the Dgroup and DartifactID values. Once you upload the JAR to Maven using this command, you can reference this JAR file using this Dependency.

<groupId>com.foo.reports</groupId>
<artifactId>jrurbersrt1.0</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>C:\Users\scottm\.m2\repository\com\foo\reports\jrurbersrt1.0\1.0\myCustomJAR_1.0.0.jar</systemPath>
</dependency>

Notice that scope element is system and systemPath references the location of the JAR file in the repository. (This dependency is used later in this article to build the AEM service) 

How can i work with 3rd party JARs when i create an OSGi bundle

When working with OSGi bundles that use 3rd party JARs (that are located in the Maven Repository), you can embed the 3rd party JAR (for example, Simple JSON JAR) into a separate bundle and deploy to AEM. See this community article/video for details.


http://scottsdigitalcommunity.blogspot.ca/2013/06/posting-form-data-to-adobe-cq-using.html

Enable CORS Access-Control-Allow-Origin in AEM

If you use the default AEM JQuery, it has a token that lets you perform AJAX operations to AEM. 

AEM is experiencing slow page loading

How does Dispatcher Caching work

The dispatcher caches only files which have an extension; and the extensions which should be considered for caching can be configured in the dispatcher config as part of the caching rules.

So you need to add an extension to your service request (e.g. ".json"), and configure the dispatcher accordingly, then the caching will work.



 Capturing comments in a default email template used by an AEM 6.2 workflow

You can write a custom workflow step and inject values you want to populate into a email template with Java logic. For example: 

//Populate the MAP with the values 
 myMap.put("topic.subject",TopicSubject); 
 myMap.put("time",timeStamp); 
 myMap.put("host.prefix",hostPrefix); 
 myMap.put("forum.url",forumUrl); 
                     
 //Declare a MessageGateway service
 MessageGateway<HtmlEmail> messageGateway; 
                        
 //Specify the EMail template 
 String template ="/etc/notification/email/html/com.day.cq.collab.forum/en.txt";
              
 Resource templateRsrc = request.getResourceResolver().getResource(template);
               
 MailTemplate mailTemplate = MailTemplate.create(templateRsrc.getPath(), templateRsrc.getResourceResolver().adaptTo(Session.class));
                      
 HtmlEmail email = mailTemplate.getEmail(StrLookup.mapLookup(myMap), HtmlEmail.class);

A solution without coding is to use the variable ${item.data.comment} in the default en.txt. To see other variables that can be used, see https://docs.adobe.com/docs/en/aem/6-2/administer/operations/notification.html#Configuring the Workflow Email Notification Service.

Join the Adobe Experience Cloud Community 

Join the Adobe Experience Cloud Community by clicking this banner




I (Scott Macdonald) am a Senior Digital Marketing Community Manager at Adobe Systems with 20 years in the high tech industry. I am also a programmer with knowledge in Java, JavaScript, C#,C++, HTML, XML and ActionScript. If  you would like to see more CQ or other Adobe Digital Marketing end to end articles like this, then leave a comment and let me know what content you would like to see.


TwitterFollow the Digital Marketing Customer Care team on Twitter @AdobeExpCare.

YouTube: Subscribe to the AEM Community Channel

Wednesday, 1 February 2017

Sign up to the AEM Dev Community Newsletter

We are starting a new program in the AEM Community. We are going to release a monthly AEM Community Newsletter. This will keep those whom subscribe up to date with everything going on in the AEM community - such as:

  • upcoming Ask the AEM Community Sessions
  • new content such as articles, Github examples, videos, etc
  • programs like Immerse and various AEM conferences
  • other interesting topics such as various announcements to contests, etc

We will release the first edition in March 2017. All you have to do is fill in this small online form:



Note: If you want to learn how to build your own HTL Newsletter component to use in your own projects - see Creating an Adobe Experience Manager Newsletter HTL component.

Join the Adobe Experience Cloud Community 

Join the Adobe Experience Cloud Community by clicking this banner




I (Scott Macdonald) am a Senior Digital Marketing Community Manager at Adobe Systems with 20 years in the high tech industry. I am also a programmer with knowledge in Java, JavaScript, C#,C++, HTML, XML and ActionScript. If  you would like to see more CQ or other Adobe Digital Marketing end to end articles like this, then leave a comment and let me know what content you would like to see.


TwitterFollow the Digital Marketing Customer Care team on Twitter @AdobeExpCare.

YouTube: Subscribe to the AEM Community Channel