Thursday, 12 February 2015

Override default String Type Value in Dialog : TypeHint CQ5

Hi Guys, 

Today i got to know how to override the default data type that is String when values are going to be store in JCR. As I found some related stuff in very old forum of CQ5 but it seems away from the search.

Use-Case : I am using my dialog with number of widgets which has xtype numberfield. So i suppose to store these in JCR as Long Type, but it take String as default type so my numbers are getting store in String type rather than Long type.

Solution is via using TypeHint. TypeHint  is one of the concept inside SlingPostServlet where it force the property to store its value with given Type. Below example demonstrate it :

1) Create a widget say num1 inside you dialog with xtype numberfield.  Same like below image :



2) Create a typehint node same as like the below image. Here the name property will be /nameofActualProp@TypeHint. 


3) Enter the values in dialog and submit it, you can view your property value as Long type in JCR rather than String.



Hope this will help

Thanks


Tuesday, 3 February 2015

Render a component at multiple sections in same page or within different page.

Hi Guys,

I will try to explain how to replicate the component's content on the different parts on page, even you can render the component's content on some other pages as well. Though it is simple if someone aware about the functionality of <cq:include /> or <sling include/>. But for those who are new and has some usecase like to render the same component in multiple parts of page, and on change of value of primary component all the dependent component replicate its value on the different sections of page.

So Lets look at <cq:include path="" resourceType=""/> . When i started work on CQ i was aware only about 

 <cq:include path="mycomponent" resourceType = "myproject/components/mycomponent"/>

To include mycomponent here my node will get create with name of mycomponent and the corresponding script will render at this time will be of myproject/components/mycomponent

So Let's you have pageA and which contains the parsys only, & you want, if you drop component in parsys it should replicate at the various sections of of pageA. So this can achieve by :

1) You dropped the component in parsys of pageA then the JCR structure will be like : 

pageA
   |---jcr:content
            |----parsys
                   |-----mycomponent

2) When you drop the component script will get execute for the resourceType mycomponent & it renders the content over page.

3) Now in the script of pageA say resourceType i.e. basepage.jsp . I included the below line.

 <cq:include path="/content/myproject/en/pageA/jcr:content/parsys/mycomponent" resourceType="myproject/components/mycomponent" />

This line say include the /content/myproject/en/pageA/jcr:content/parsys/mycomponent resource which obviously will have content stored as we have dropped it previously inside parsys and entered the content it that. & To render its content we will use the script of myproject/components/mycomponent component.




The one thing that was new for me was the explanation of path.

Hope this will help.
Thanks

Monday, 2 February 2015

Themes in clientlibs to include specific resources AEM6/CQ5

Hi Guys,

As we know, clientlibs in CQ5 use to include our js/css files via one line of code in our script file apart from other benefits. One thing that i had in my mind is what would be the case, If I want to add only few JS files via my <cq:includeClientLib />. Now got the answer which is might not be the full proof but yes, fulfill the aim of a developer. Answer is via Themes.

Use-Case : Have 3 JS files alpha.js,beta.js,gamma.js. I have Clientlib with category themetest. So with <cq:includeClientLibs /> how can i selectively inject the js files inside my script file.

Below demonstration will exaplin you how :

1) Create a clientlibrary folder with name say clientlibtest with categories themetest.
2) Create js folder and add two file say alpha.js & beta.js inside it.
3) Register their entries in js.txt file.
4) create a folder named themes under your clientlibtest folder.
5) Create a clientlib folder with any name say themegamma, keep the categories of themegamma should be same as clientlibtest i.e themetest
6) Create js folder under themegamma and add file say gamma.js inside it.
7) Register its entry in js.txt file which you created inside themegamma.

Below is the snapshot :




Now if you write the statement:

<cq:includeClientLib js="themetest" themed="true"/>
In that case only gamma.js will gets load.

<cq:includeClientLib js="themetest" themed="false"/>
In that case alpha.js & beta.js files will gets load.

<cq:includeClientLib js="themetest"/>
In that case all of js files will gets load.


Hope this will help.

Thanks

Sunday, 1 February 2015

Enable SSL in AEM6

Hi Guys,

In this blog, I'll provide the demonstration of how you can enable SSL on the AEM6 on Author Instance. I have done it earlier in CQ5 via felix console, but in AEM6 I think some fields are added & some are missed as in below image :


Here some fields are new like truststore etc. AFAIK, Also keystore alias is also not available in this configuration, so I faced some issues to configure this. But some help from Adobe Docs worked.

Below are the steps to follow :

1) Navigate to the directory in your local AEM instance & generate the keystore via below command:

user@user-Aspire:/media/user/Misc/SelfWork/Author/crx-quickstart/conf$ keytool -genkeypair -keyalg RSA -validity 3650 -alias cqse -keystore cqkeystore.keystore -keypass password -storepass password -dname "CN=sbroders-w7, OU=CQ, O=Adobe, L=Ottawa, S=Ontario, C=CA"

This will generate the keystore cqkeystore.keystore under /crx-quickstart/conf directory.

2) Navigate to the /apps and create the folder system, and apply the configurations as per the adobe docs. Finally your configuration in crxde will look like :


Restart you AEM Instance. 

3) Hit https://localhost:5433/ and proceed.

Hope this will help.
Thanks






Wednesday, 28 January 2015

How to Make Suggestions Available in JSP Files in CQ5/AEM6 using JSPC plugin

As a newbie in AEM one of the challenge that I was faced was the suggestions availability inside AEM. Sightly is emerging to replace the JSP files of components but for the time being if we are working on the JSPs and it takes much time to code the jsp file, this blog will help in enabling the suggestions inside jsp files using maven-jspc-plugin. To make this work I used the below project structure.

/apps/
     |--->aemproject/
                    |--->components
                    |--->config
                    |--->install
                    |--->templates
                    |--->init.jsp
                    |--->global.jsp[which is included inside init.jsp]

Now if we have <%@include file="/apps/aemproject/init.jsp" %> inside our template/component then we will have suggestions enabled for their respective JSPs.

Open your content module's pom.xml, and then add the dependencies in pom.xml as per your global.jsp. i.e
       <%@page session="false" import="javax.jcr.*,
        org.apache.sling.api.resource.Resource,
        org.apache.sling.api.resource.ValueMap,
        com.day.cq.commons.inherit.InheritanceValueMap,
        com.day.cq.wcm.commons.WCMUtils,
        com.day.cq.wcm.api.Page,
        com.day.cq.wcm.api.NameConstants,
        com.day.cq.wcm.api.PageManager,
        com.day.cq.wcm.api.designer.Designer,
        com.day.cq.wcm.api.designer.Design,
        com.day.cq.wcm.api.designer.Style,
        com.day.cq.wcm.api.components.ComponentContext,
        com.day.cq.wcm.api.components.EditContext"
        %>
       
Now add the maven-jspc-plugin inside the same file. Below is the snapshot of pom.xml need to add.

        <pluginManagement>
            <plugins>
                <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                        <lifecycleMappingMetadata>
                            <pluginExecutions>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>org.apache.sling</groupId>
                                        <artifactId>maven-jspc-plugin</artifactId>
                                        <versionRange>[2.0.6,)</versionRange>
                                        <goals>
                                            <goal>jspc</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <ignore/>
                                    </action>
                                </pluginExecution>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>org.apache.maven.plugins</groupId>
                                        <artifactId>maven-clean-plugin</artifactId>
                                        <versionRange>[2.4.1,)</versionRange>
                                        <goals>
                                            <goal>clean</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <ignore/>
                                    </action>
                                </pluginExecution>
                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>

            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-resources</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/jsps-to-compile</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>src/main/content/jcr_root</directory>
                                    <excludes>
                                        <exclude>libs/**</exclude>
                                    </excludes>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.sling</groupId>
                <artifactId>maven-jspc-plugin</artifactId>
                <version>2.0.6</version>
                <executions>
                    <execution>
                        <id>compile-jsp</id>
                        <goals>
                            <goal>jspc</goal>
                        </goals>
                        <configuration>
                            <jasperClassDebugInfo>false</jasperClassDebugInfo>
                            <sourceDirectory>${project.build.directory}/jsps-to-compile</sourceDirectory>
                            <outputDirectory>${project.build.directory}/ignoredjspc</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-clean-plugin</artifactId>
                <executions>
                    <execution>
                        <id>remove-compiled-jsps</id>
                        <goals>
                            <goal>clean</goal>
                        </goals>
                        <phase>process-classes</phase>
                        <configuration>
                            <excludeDefaultDirectories>true</excludeDefaultDirectories>
                            <filesets>
                                <fileset>
                                    <directory>${project.build.directory}/jsps-to-compile</directory>
                                    <directory>${project.build.directory}/ignoredjspc</directory>
                                </fileset>
                            </filesets>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>com.day.jcr.vault</groupId>
                <artifactId>content-package-maven-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <group>AEM Training</group>
                    <filterSource>src/main/content/META-INF/vault/filter.xml</filterSource>
                    <embeddeds>
                        <embedded>
                            <groupId>${project.groupId}</groupId>
                            <artifactId>Training-bundle</artifactId>
                            <target>/apps/aemproject/install</target>
                        </embedded>
                    </embeddeds>
                    <targetURL>http://${crx.host}:${crx.port}/crx/packmgr/service.jsp</targetURL>
                </configuration>
            </plugin>
        </plugins>
        </pluginManagement>

Build codebase -- mvn clean install -P yourbuildprofile

You can see the suggestion available via ctrl+space inside your jsp file.



Hope this will help.

Thanks

Sunday, 23 November 2014

Introduction to Sling Servlets in AEM

Hi All

This blog intended to the beginners of CQ5 to understand what are the sling servlet and how to create a very basic servlet. We can create the servlet in AEM by two ways :

1) By using Sling-specific @SlingServlet annotation.
2) By using  generic maven-scr-plugin annotations.



Here Below i'll show you an example how to resolve the servlet as per the resourceTypes.

Step 1 : Create a component /apps/AEMProject/components/content/servletchecker.
Step 2 : Inside servletchecker.jsp Add the below code.

 <form name="form" method="post" action="<c:out value="${resource.path}" />">   
   <input type="submit" />   
  </form>   

Here resource.path refer to the content node, that might all aware :)
Step 3 : Create the servlet as follows :
 @Component   
  @Service(Servlet.class)   
  @Properties({   
    @Property(name = "sling.servlet.resourceTypes" , value = "AEMProject/components/content/servletchecker" ),   
    @Property(name = "sling.servlet.methods" , value = "POST" )   
  })   
  public class ConfigurationChecker extends SlingAllMethodsServlet {   
    private static final long serialVersionUID = -7945683216509362012L;   
    private final static Logger logger = LoggerFactory.getLogger(ConfigurationChecker.class);   
     @Override   
     protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {   
           response.setContentType("text/plain");   
           logger.info("Success");   
     }   
  }   

Here as you can see action is resource.path, in my case it is /content/AEMProject/English/test/jcr:content/par/servletchecker
At this node Sling will look for AEMProject/components/content/servletchecker resource as we registered in our servlet, If it gets resolve then the servlet execute.

Also one can use the selectors to resolve in that case your jsp would be like :
 <form name="frm" method="post" action="<c:out value="${resource.path}" />.email">  
   <input type="submit" />  
 </form>  


And add the property on your servlet :
@Property(name = "sling.servlet.selectors" , value = "email")

Below would be the code :


 @Override  
        protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {  
                   response.setContentType("text/plain");  
                   String selectors[] = request.getRequestPathInfo().getSelectors();  
                   logger.info("Resource is "+resourceType);  
                   for(int i=0 ; i<selectors.length ; i++)  
                   {  
                        String selector = selectors[i];  
                        if(selector.equals("email"))  
                        {  
                             logger.info("Work with Email");  
                        }  
                   }  
                   logger.info("Success");  
        }  

Thanks



Wednesday, 12 November 2014

AEM integration with Google Analytics and Google Tag Manager




Google Analytics and Google Tag Manager are analytical tools that help to analyze the statistics of web site which is helpful as per the business prospective. Organization can monitor which are widely used web pages and which are least use by the visitor. Here I am going to demonstrate how you can integrate AEM with Google Analytics and also will use the GTM tags to use in AEM.


1)      Organization must have the google analytics account, If one already have then we can get the tracking code by navigate to the admin tab then click on the tracking info section and copy your tracking id and tracking code on some txt file as these two properties initially we need.
2)      Go to tools section of AEM. Navigate to the Generic Analytics Snippet and create the new configuration. Inside Snippet JavaScript Code just paste your tracking code & ok.
 
1)      We need to add this cloudservice onto the page that we want that we want to analyze.  If we want to analyze the whole site then just add that cloud service onto the topmost page of hierarchy like en-US.
2)      Now login to the Google Tag Manager. Follow the link to create a tag that will track outbound link. Below is the snapshot of rule that I applied. Also make sure you will have the js code that you get from GTM  inside body.jsp or what they mentioned in blog.




1)      For testing you can also debug your tag via overview then upon clicking preview button.
2)      Open you site hosted on 127.0.0.1:8502 then open some page and click on any external link.  Now any click event that redirect you out of the site will get track.
3)      We can check the analytics. Go to the reporting tab and in search look for the event you will find Behavior >Event >Page the you will be able to see events. Click on the page on which event fired.