CQ5 Clientlib explained by example

In this blogpost I will go through the basic functionality that the ClientLibraryFolder offers, and how you can utilize that with the <cq:includeClientLib /> tag.
The “clientlib” functionality will manage all your Javascript and CSS resources in your application. It takes cares of dependency management, merging files and minifying content.

The following application scenario will be explained :
- multiple components with their own Javascript and CSS files
- global Javascript and CSS files
- /apps folder is not available via the dispatcher (recommended)
- CSS resources have to go in the <head>, Javascript resources at the end of the page
- Resources need to be minified
- Some resources need to be merged

Let’s get started!

Step 1: Creating components and clientlib nodes

First we make a few components, in this example 3 components are used.

 

 

 

Next we are going to add a “clientlib” node of type cq:ClientLibraryFolder, inside this node the Javascript and CSS resources are stored.

 

 

 

 

 

 

Add a property to every clientlib-node called “categories” of type String[] with the single value of “myproject.components”. (To get a String[] type click the Multi button ).

 

 

 

Your components-folder will look now like this:

 

 

 

 

 

Step 2: Adding Javascript and CSS resources

Now we are going to add some simple Javascript and CSS resources in the clientlib-node.

CSS (first.css):
.firstContainer {
margin-top:10px;
}

Javascript (first.js):
/*
* This is the comment of the function
*/
function getNameFirst() {
// return the name
return "some value";}

js.txt
This mentions all the Javascript resources of the clientlib, in this case one line :

first.js

css.txt
Same as for js.txt, but then for all the CSS resources, so also one line:

first.css

Your components folder will now look like this:

 

 

 

 

 

 

 

 

The configuration of the components are now finished.

Step 3: Using <cq:includeClientLib />

Now the components are finished we can now use the <cq:includeClientLib /> to write out the references inside the <head> of our template. You can also choose to write out certain references in other places in the page, for example some Javascript at the end of the page.

We start with putting the following into the <head>

<cq:includeClientLib css="myproject.components" />


<cq:includeClientLib js="myproject.components" />

Note that “myproject.components” is the value of the “categories”-properties of the clientlib-node.

This results in the following HTML-output:

<link rel="stylesheet" href="/apps/mycomponents/MyThirdComponent/clientlib.css" type="text/css">
<link rel="stylesheet" href="/apps/mycomponents/MySecondComponent/clientlib.css" type="text/css">
<link rel="stylesheet" href="/apps/mycomponents/MyFirstComponent/clientlib.css" type="text/css">

<script type="text/javascript" src="/apps/mycomponents/MyThirdComponent/clientlib.js"></script>
<script type="text/javascript" src="/apps/mycomponents/MySecondComponent/clientlib.js"></script>
<script type="text/javascript" src="/apps/mycomponents/MyFirstComponent/clientlib.js"></script>

This has a few downsides:
- The resources are retrieved from /apps
- 6 server calls have to be made to fetch the resources
- Application structure is exposed
Step 4: redirecting resources via /etc/designs and merging into single files

What we want is that the user gets the resources from /etc/designs/<project>, so that /apps can be closed for the production configuration. And on top of that we want that the resources will be merged into a single .js/.css reference.

Create a new folder “aproject” in /etc/designs, then create the structure as shown below. The js.txt and css.txt should be empty files.

 

 

 

 

 

The clientlib-node has the following properties:

 

 

 

With the embed-property it embeds all the resources of “myproject.components”

Now change the attributes in the <head> section to:

<cq:includeClientLib css="myproject.all" />

<cq:includeClientLib js="myproject.all" />

This results now in the following HTML output:

<link rel="stylesheet" href="/etc/designs/aproject/clientlib.css" type="text/css">

<script type="text/javascript" src="/etc/designs/aproject/clientlib.js"></script>

If you open these files you will see that the three js/css resources are merged into one file. And although the resources are located in the /apps-folder all references are now done via the /etc/designs folder.

Step 5: Dependencies

Another property you can add to the clientlib-node is “dependencies”, this way you can define depedencies between clientlibs.

Let’s add a dependency on cq.jquery:

 

 

 

 

When you now reload the page the dependency is written:

<script type="text/javascript" src="/etc/clientlibs/foundation/jquery.js"></script>
<script type="text/javascript" src="/etc/designs/aproject/clientlib.js"></script>

Step 6: Minify and Gzip

To deliver a better performance you can enable “Minify” and “Gzip” for the “Day CQ HTML Library Manager” in the Felix Configuration console (http://server/system/console/configMgr). These settings are recommended for production installations.

When you now look at this resource “/etc/designs/aproject/clientlib.js”, it results in this:

function getNameThird(){return"some value"
}function getNameSecond(){return"some value"
}function getNameFirst(){return"some value"
};

So all comments and spacing are removed to save download-time.

FAQ

Q: I don’t want to have all my Javascript references in the <head>
A: Move the <cq:includeClientLib js=”your-category” /> to the right location in your template, you can use <cq:includeClientLib /> multiple times

Q: Where are the generated files stored in CQ?
A: They are in /var/clientlibs

Q: When developing I want to have single file references in my HTML
A: Enable the debug-option in the HTML Library Manager

Q: Is there a console so I can see the depedencies?
A: Yes, look at this page http://server/libs/cq/ui/content/dumplibs.html

Q: Are there debugging options available?
A: Yes, ?debugClientLibs=true writes out single files
A: Yes, ?debugClientLibs=true and CTRL+SHIFT+U gives you timing info

Posted in Experience Services | Tagged , | 3 Comments

CQ5 Developer tricks

While working with Adobe CQ5 every now and then you discover some new tricks or options, here the list that I use daily:

Remove #cf/
Don’t want to see/wait for the content-finder while refereshing pages, just remove #cf/ in your url.

?debug=layout
Shows you all details of the components used on your page

?debugConsole=true
Runs Firebug Lite inside your browser

?wcmmode=(edit|preview|design|disabled)
This parameter sets your WcmMode in the specified mode, makes testing for a particular WcmMode easier .

?debugClientLibs=true
Writes out all Clientlib categories as separate files (check your HTML-source).

CTRL+SHIFT+U
In combination with ?debugClientLibs=true will show you timing information of your page

http://server/libs/cq/ui/content/dumplibs.html
Shows you all information around the clientlibs used in your CQ5-environment.

If you have other tricks, let me know and I will add them to the list…

Posted in Experience Services | Tagged , , | Leave a comment

Getting to know the Externalizer

In this post I want to highlight the beauty of the Externalizer that is still unknown to a lot of developers.

Sometimes in your CQ5 application you want to get hold of the external url of a particular page, for example if you want to specify the url in your opengraph meta tag.

<meta property="og:url" content="http://mywebsite/myniceurl/mynicepage.html"/>

What you see quite often is this pattern:

<%
String externalUrl = myPage.getPath() + ".html";
%>
<meta property="og:url" content="<%= externalUrl %>"/>

This will result in something like :

<meta property="og:url" content="/content/myinternalpath/myinternalpage.html"/>

This method doesn’t respect settings like, vanity-urls, resource mappings, aliases, external host addresses.

What you should use is the Externalizer, that has methods like .absoluteLink() and .relativeLink().

<%
Externalizer externalizer = bindings.getSling().getService(Externalizer.class);

String externalUrl = externalizer.absoluteLink((SlingHttpServletRequest)request,
request.getScheme(), currentPage.getPath());
%>

This now results in the nice external url you want to share with your customers:

<meta property="og:url" content="http://mywebsite/myniceurl/mynicepage.html"/>

A very easy way to test this while being in development is to set an alias (Advanced-tab on Page properties) on your page. You will see now that the alias is used in the external url, while your path remains the same.

Posted in Experience Services | Tagged , , | Leave a comment

The Future of LiveCycle

Since Adobe announced its increased focus on Digital Marketing and Digital Media, the LiveCycle team has met with dozens of customers and partners to discuss the future of LiveCycle.   They are all passionate about our technology and the solutions we provide and have been excited when we have shared our plans with them.  I’d like to share those plans more broadly with you.

To start with, we remain committed to creating further innovations within the LiveCycle product line and supporting LiveCycle customers.  We have a large install base of customers using LiveCycle for Business Process Management, Forms, Security, and Document Generation based applications and solutions that are mission critical to their business.  Adobe fully intends to continue to support, maintain, and enhance the products that they are using.

There are  a number of priority areas that we will make investments in going forward.  The areas which we see as the core offering for LiveCycle ES and are prioritizing our engineering investment around are:

  • Modules: Reader Extensions, Forms, Output, Digital Signatures, Rights Management, Process Management, PDF Generation
  • Tools: Workbench, Designer
  • Solutions: Correspondence Management
  • ECM Connectors: SharePoint, IBM Filenet, Documentum
  • Advanced Offerings: Data Services

We’ve already begun to deliver on our commitment to invest and innovate.  In December, we shipped a service pack for our August 2011 release and also shipped a new feature-packed version of LiveCycle Data Services for Java EE.  Next on our agenda, we will release ECM connector enhancements and updates in the first quarter of 2012.  Looking forward to the second half of 2012, my team is already hard at work on the next version of LiveCycle ES that will include many product feature enhancements.  Keep an eye on the product blogs and forums to see how they will be leveraging HTML across LiveCycle as they start ramping up for prerelease drops.

As we mentioned in an earlier post, Adobe will have a direct selling relationship within select markets like government and financial services.  Additionally, we will leverage our long-standing partner community to represent LiveCycle across all markets.

I hope this helps you understand the future of LiveCycle and I look forward to sharing more information about our 2012 release as the year progresses.

Arun Anantharaman

Vice President and General Manager

Posted in ADEP, Adobe LiveCycle ES, Adobe LiveCycle ES2 (9.0.x), Document Services, Experience Services, General Interest | 8 Comments

Sanity Checks for CQ5 Installations

In this blogpost I listed some basic checks you can do after you have done a (production) installation of CQ5(.4). The checks can mostly be done via the browser, and will give you very quickly an rough idea whether you are almost done, or still has to start.

1. Admin screens

The following urls should not be accessible:

http://yourwebsite/system/console

http://yourwebsite/system/sling/cqform/defaultlogin.html

http://yourwebsite/crx/de/index.jsp

If these pages are accessible, then you have to revisit the security settings mentioned in this document :

http://dev.day.com/docs/en/cq/current/deploying/security_checklist.html#Restrict%20Access%20via%20the%20Dispatcher

Continue reading

Posted in Experience Services | Tagged | Leave a comment

How to Fix com.adobe.idp.scheduler.SchedulerException: Failure Occurred During Job Recovery

Problem Scenario:

LiveCycle uses Quartz scheduler. Typical use case is when “watched folder” endpoint related schedules get translated as quartz triggers. Quartz takes care of executing the trigger based on frequency and updates a table with the latest execution count.

We ran into a production scenario where customer was running LiveCycle 8213 against Oracle 10g db and one fine day their weblogic servers wouldn’t start.

Continue reading

Posted in General Interest | Tagged , , , , , | Leave a comment

LiveCycle Data Services for Java EE 4.6 now available

Here’s another announcement! LiveCycle Data Services version 4.6 is now generally available. It is the latest update to the JEE or LiveCycle version of Data Services and it is a feature-rich major release, including expanded support for mobile applications (HTML5/JavaScript, native iOS and Java/Google Android), adds an SAP Connector, introduces managed remoting, and enhancements to model driven development and the offline synchronization framework.

For more information check out the following two sites:

Product overview on Adobe.com: http://www.adobe.com/products/livecycle/dataservices/

LiveCycle Developer Center on the Adobe Developer Connection: http://www.adobe.com/devnet/livecycle/dataservices.html

For existing customers with maintenance and support contracts, the Data Services 4.6 release along with Flash Builder 4.6 has been automatically pushed into your Licence Web Site (LWS) account. This includes ADEP/LiveCycle V10 customers that have licence rights to Data Services.

Juergen Hauser – Sr. Product Manager – LiveCycle Data Services

Posted in ADEP, Experience Services, General Interest | Tagged | Leave a comment

ADEP/LiveCycle v10 SP1 Now Available

I’m pleased to announce that the first service pack for ADEP/LiveCycle v10 is now available. It is made up of two parts; Document Services SP1 for the LiveCycle Modules (Forms, Output, Reader Extensions, Process management …) and Experience Services SP1 (update to Experience Services Quick Start containing Mosaic and Experience Services based Data Services).

The service pack extends support to Flash Builder 4.6 which has been made available to all customers with ADEP/LiveCycle v10 in their Adobe Licence Web Site (LWS) accounts.

The Document Services SP1 is available at this link. An Adobe ID is required to access the page. The Experience Services SP1 will be available on Package Share in mid December 2011, the link above will be updated when it is available.

Neal Davies – Sr. Product Manager – LiveCycle

Posted in ADEP, Adobe LiveCycle ES, Adobe LiveCycle ES2 (9.0.x), Customer Experience Solutions, Document Services, Experience Services, General Interest, Uncategorized | Tagged , , | 1 Comment

Using the i18n Translator

This week a colleague of mine showed me the default i18n translation functionality of CQ5.4 which I wasn’t aware of. And I don’t want to keep this one for myself.

It is available via this url : http://localhost:4502/libs/cq/i18n/translator.html (change host and port to your own needs).

Here’s an example of the UI that is presented with the translator:

You have a lot of options available around searching, exporting, importing etc.

Also, with the list-view Administrators can easily see what content is not yet translated.

Posted in ADEP | 2 Comments

Beyond String – @TypeHint to the Rescue

Based on some questions from a partner I had to investigate whether it was possible to store values for widgets you define as part of your CQ5 custom component as something else than String. Guess what…. it’s possible (not that I was surprised…).

Storing JCR content with a specific type is possible using the @TypeHint property, as is documented as part of the Apache SlingPostServlet (more specifically in the section on Controlling Content Updates with @ Suffixes).

However, how can @TypeHint be ‘reused’ such that also the properties of a custom component can be saved as something else than String? With some help of engineering, follows a tutorial…

Continue reading

Posted in ADEP, Experience Services | Tagged , , , | Leave a comment