It is very common to see scriptlets inside AEM JSPs. I know! is not a very good looking JSP.
To improve the code readability JSP Standard Tag LibraryĀ (JSTL) is recommended. There might be scenarios where JSTL is not enough and some coding is needed inside the JSP context. A good approach to handle this, and keep avoiding scriplets is Custom Tag Libraries.
A custom tag library is kind of a JSP helper for your code. You can call a custom tag library and make it perform some task(s), and then retrieve the values from the context.
By using this approach you can create reusable, maintainable, scalable Java classes, that might help different AEM components on similar tasks.
For a taglib to be used there are a couple of rules that need to be meet.
The OSGI bundle containing the tag library classes needs to have the aĀ Tag Library Descriptors file (.tld).
āA tag library descriptor is an XML document that contains information about a library as a whole and about each tag contained in the library. TLDs are used by a web container to validate the tags and by JSP page development tools.ā
This TLD needs to have a unique identifier between all system available tag libraries. This identifier will be used to reference the library from a JSP context.
On this post I will describe you how to setup tag library support.
Maven Plugin Changes
1. Setup POM properties to include Description and URL properties. This properties will be used later by a maven plugin.
2. Setup theĀ maven-bundle-plugin to the taglib project POM file.
The plugin will contain information like the export package (com.myproject.taglib.*).
3. Setup the mavenĀ jsptld-maven-plugin to the taglib project POM file.
This will allow the plugin to look for tag annotations and it will automatically generate the TLD information based on that.
Maven dependencies
Now letās review the maven dependencies I've used to setup tag libraries.
The libraries that I normally include are:
squeakysand-jcr-taglib :Ā A JSP taglib for working with JCR resources in a Servlet environment.
squeakysand-jsp :Ā Classes and annotations for working with JSP technologies.
squeakysand-sling-taglib :Ā Resources for working with Apache Sling from a Java Servlet environment.
Our project is ready, now we can start coding our classes that will become on custom tags and part of our custom tag library.
Here I will conclude this post, on the next one I will explain the tag library class and how to use the tag library from a JSP.
Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
ā Live Streamingā Interactive Chatā Private Showsā HD Quality
Anya is LIVE right now
FREE
Free to watch ⢠No registration required ⢠HD streaming
Sling Models is framework that will let us map Sling objects to POJOs. The idea is to create model objects to represent resources.
This approach uses entirely annotations to build its structure, and has support to work with both classes and interfaces.
On this post I will explain how to incorporate sling models into your project to map resources into POJOs.
SLING MODEL Bundles
AEM 6 has Sling Models support OOTB, to make it work with CQ5.6 some extra steps will have to be followed. In my case, I am using AEM 6 SP2.
To find out if your AEM/CQ installation is Sling Model ready you can visit the web console and check if the OSGI bundle for Sling Model exists and verify that it is active.
To do that you can visit the /system/console/bundles URL in your local instance and look for the Sling Model bundles.
Note: Take a close look at the bundles version.
Project Setup
Once your AEM instance is ready you can begin the project setup:
First you will have to create a Java project that later will be deployed into OSGI as a bundle. This bundle will have the Sling Model packages.
The POM of this project needs to have theĀ maven-bundle-plugin declaration like in the following screenshot.
The <Sling-Model-Packages>section is very important. This will let OSGI know that the package path described there contains Sling Models classes/interfaces, and it will scan through it looking for the annotations. PLEASE donāt skip these plugin lines otherwise your models might not be mapped correctly.
SLING Model Interface or Class
Now you are ready to create models either using classes or interfaces. There are several annotations that will help you on this setup. The most common annotations are:
@Model Used to specify that the class represents a Sling Model.
@Inject Used to specify that a property represents a resource property.
Note: There are several others annotations and variations for Sling Models that might suite for different needs.
On my test case I've declared a UserInfo interface with two properties. The properties will be injected using the getter declarations.
Now that we have our Sling Model ready, we just need to test it, for this I've created a simple servlet that pulls the resource and adapts it to our Sling Model.
The test Servlet will pull the resource by using the resource resolver:
Then you can just print the different properties using the userInfo object.
Same thing you can do in an AEM component JSP, you just need to adapt the resource to the Sling Model.
As I said earlier, using Sling Models is a great approach to handle different scenarios, including coding unit tests. Also this is just a simple test case, there is a bunch of different scenarios where extended approaches can be implemented.
While looking for some instructions on how to create a custom widget I landed on a great website that I wasn't aware of beforeĀ ACS AEM Commons.
AEM Commons is a package containing a bunch of different common and very useful features. I think the lemma of this packages say it allĀ āThe wheel doesn't need reinventingā.
The Installation of this tools is very easy, it can be done using maven or manually deploying the package, this can be done via package manager.
The package can be found in GitHub.
The feature that I used at first was theĀ āMulti Field Panelā. This feature is inside theĀ āCustom Widgets and Validatorsā section.
I am pretty sure you as a developer have faced the need to create a multifield property that contains more than one type of fields.
The traditional way to workaround this requirement is to create a custom widget. This for sure take some time, plus it might very complex to maintain it and reuse it for multiple purposes.
Now, with the AEM Commons tools, this requirement and necessity is covered.
The field to be used isĀ multifieldpanel.Ā It will store the content in a json string. The tools also offer a custom tag to read this property.
āThe multifieldpanel widget is a widget which enables the management of complex items in a traditional multifield. These complex items are composed of multiple widgets.ā
JSON:
{"term":"term","definition":"a word or phrase used to describe a thing"}
To install CQ/AEM on your local all you need is the CQ jar installation file and a license.properties. As a developer the only way to get these files is from Adobe official AEM training, and off course the license is a developer license, this license is not a distribution license and is not a commercial license.
According to me, the hardware requirements to run AEM on a local development environment without feeling slowness and issues are:
8+ RAM
30GB+ HD available space
Java 1.6+
For default the AEM installation folder is the folder where the jar and license files are placed. This is why I recommend placing the jar on a structure similar to the following:
\..\..\cq\author\ Ā Ā for the author instance
\..\..\cq\publish\ Ā for the publish instance
Naming the .jar file:
The name of the jar file is very important, the name contains information as the type of instance (author or publish) plus the port on which the instance will run.
The convention sets the following:
Default author port: 4502
Default publish port: 4503
If there is a cluster all author instances should start from 4502 and up skipping one. i.e. 4502, 4504, 4506, 4508, etc. Author instances are on even ports.
If there is a cluster all publish instances should start from 4503 and up skipping one. i.e. 4503, 4505, 4507, 4509, etc. Author instances are on odd ports.
With this said lets check an example of the jar file for an author instance.
cq56-author-4502.jar
cq56: the version of the instance.
author: the instance type.
4502: the port the instance will be running on.Ā
Running the instance:
To start AEM open up a command window/terminal and run the next command:
The -gui param starts up a GUI interface. The GUI interface will let you know through a progress bar the status of the start up, and using the interface you will be able to stop the instance later.
Folder Structure:
After the instance has started up you will notice that a new folder has been created at the same level as the jar file. The folder name is 'crx-quickstart' and this folder contains the complete instance setup and instance content.
If you have followed this post, after starting up your local author instance, you will find your instance control panel at:
On a dev server where I have an AEM6 project running I noticed a weird message on the logs and the author instance wasn't starting up correctly.Ā
After doing some system health check I noticed the hard drive space was close to be full. This was weird since the only active project on the server was the AEM6 project.
I started checking where the HD space was being dragged and noticed that the size of the segmentstore folder (../crx-quickstart/repository/segmentstore/) was huge.
After some research I found an Adobe linkĀ on how to reduce/compact the size of the segment store which, off course, shouldn't be that big.
I followed the manual offline compaction process using theĀ 'oak-run-1.0.8.jar'Ā to reduce the size. The size went down from 60GB to 4GB.
After doing additional research, I found out that to prevent this strange issue with the /segmentstore/, AEM6 SP1 should be installed (SP2 has also been released, its release notes say that SP1 is included on SP2).
This said, after SP1 was installed I've monitored my AEM6 instance for a month now, and its growth in size is back to normal.
Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
ā Live Streamingā Interactive Chatā Private Showsā HD Quality
Anya is LIVE right now
FREE
Free to watch ⢠No registration required ⢠HD streaming
I've working with CMS for a few years now. I am glad I have had the opportunity to work with CMS (Sitecore, CQ/AEM) that have been always in the top #3, and this is not said by me ;) the Gartner quadrant guarantees that.
My Java background gave me the opportunity to start working with CQ/AEM.
The plan was getting the official Adobe training, but before that I wanted to do some research and play a bit with the CMS.
At this point I was surprised with the amount of information that me as a developer was able to find in the web, the information was shorter than I expected.
Anyway with some information from here and from there I was able to get a better general idea on how AEM works. This for sure helped me on the training days.
This is why a couple of years later, and some knowledge I've gain on AEM, I decided to start this blog and perhaps help developers go inside the AEM world.
If you are a developer who is starting on AEM, this post is for you.
These ideas might give you a better understanding on the CMS:
Adobe its the company that owns AEM.
AEM stands for Adobe Experience Manager.
AEM former name is CQ.
AEM is a Java based CMS.
It is an enterprise CMS.
Current version as of today, is AEM 6.
Perhaps for now the most popular version has been CQ 5.6.
AEM doesn't need a database to run. It uses a Java Content Repository (JCR).
The installer is a jar file. (I got it on my official training, not sure if there is some other way to get it as a developer).
AEM key principles:Ā
"Everything is content".
Data first, structure later (maybe).
Content hierarchy has to be really well thought.
Names should have a meaning. IDs are not for AEM ("IDs are evil").
References are not for AEM either. Referencial Integrity is the base principle for a relational database. And remember that AEM doesn't use a Database, it uses a Java Content Repository.
AEM rocks!
Before I finish this post I would like to give you a tip:
When I started on this CMS I always used to compare, on functionality terms, how things work between Sitecore and AEM. This really didn't help to make concepts clearer and cleaner. They are, or better said, AEM has very different concepts and approaches for templates, content, designs, etc. Please clear your mind in CMS concepts before starting to learn AEM.
I wouldn't like to extend more this post and make it hard to read. Hopefully I've given enough general information for a first post.
The idea of this blog is to provide some useful posts to the CQ / AEM community. I'll try to write posts from my AEM experiences. Here you will find from basic to advanced topics, in general the idea is to give the audience important information for their AEM education.