Coding for CQ/WEM can be quite confusing sometimes, as confusing as it is whether it's CQ or WEM. This post is about basic WEM Code samples (in JSP) using CQ scripting objects on top of JSP implicit objects. First of all, let me be clear, since Adobe acquired Day Software, the name of Day CQ (Comuniqué) had changed to WEM (Web Experience Manager), thus CQ and WEM are interchangeable.

When you develop the jsp script of a AEM component, most of the cases you'd include following code at the top of the JSP script:

<%@include file="/libs/foundation/global.jsp"%>

It declares and exposes the regularly used scripting objects defined by the sling taglibs, cq taglibs and jstl taglibs at your disposal in JSP. Assuming you have the above line in your .jsp, the following code samples show you some very basic tasks that you usually have to accomplish.

Access Current Resource and Its Properties

Most of the time, you'd access the current page, current component, current whatever, etc. The global.jsp brings many exposed variable to you to access current resource via EL expression:

[1] The xpath syntax to match resources that has property named 'transporUri'.

Access Property of a Specific Resource Path

Once you have a Resource, you can adapt a Resource to a Page, adapt a Resource to a ValueMap, a Node, or an InputStream, etc., then access the ValueMap for the property value. In your JSP file, do this: