Sunday 18 May 2014

CQ Defined objects


CQ and Sling has provided some custom tag libraries which could reduce the development effort. <cq:definedObjects/>, <sling:definedObjects/>  has some regularly used scripting objects.

If "/libs/foundation/global.jsp" is included in the script, these tag libraries will get included by default

Objects defined by Sling:

slingRequest – SlingHttpServletRequest  Object
  <%ResourceResolver rr=slingRequest.getResourceResolver();%>
But resource resolver is already available as a defined object explained below

slingResponse – SlingHttpServletResponse Object

request - HttpServletRequest Object

response -  HttpServletResponse Object

resourceResolver - Current requests ResourceResolver Object                  <%=resourceResolver.getResource("/apps/blog/components/checkboxtest").getName()%>

sling - SlingScriptHelper Object which provides methods for scripts.Most commonly used to fetch an OSGI
           service reference
            <% QueryBuilder queryBuilder=sling.getService(QueryBuilder.class); %>

resource - The current resource same as slingRequest.getResource();
 <%=resource.getResourceType()%>

currentNode - Current resource node Object
      <%=currentNode.getName()%>
log - SLF4J logger
<%log.info("Logging test");%>

Objects defined by CQ:

componentContext - The current component context Object
                                 <%=componentContext.getComponent()%>

component - The current component Object
                     <%=component.getComponentGroup()%>

currentPage - Current page object
                       <%=currentPage.getPath()%>

pageManager - Page manager object useful for performing operations on page
                         <%=pageManager.getPage("page path")%>

pageProperties - Page properties that can be used directly rather than reading them from page again
                           
properties - properties of the current resource
                    <%STring arr[]=properties.get("myProperty",String[].class);%>


More details on the tag libraries available at
http://wem.help.adobe.com/enterprise/en_US/10-0/wem/howto/taglib.html



Friday 16 May 2014

Checkbox component

Creating a Selection (checkbox) component in Adobe CQ

Section below describes step by step procedure for creating checkbox component in Adobe CQ

1.Right click on the folder where you want to create the component and select "Create Component"

2.Enter the details for Label ,Title and Group ,make sure you enter different text for each.
       E.g  Label :checkbox ,Title:My checkbox ,Group: MyComponents
 

      The component will get created along with the jsp associated with it.



3.We need a dialog ,which will enable us to interact with the user.
For that right click on the component and select "Create Dialog",now
your component looks like something as shown .

 


4.Right click on the node "tab1" (which is be created as a part of dialog)
  and create a node by name "items" and type as "cq:WidgetCollection".

5.Right click on "items" and create node by name "checkbox" and type as      "cq:Widget"

6.Add properties to checkbox node

name: "xtype"  value: "selection"
name: "type"    value: checkbox"
name: "name" value: "./checboxtest"


7. Right click on node "checkbox" and create a node    by name"options" and type"cq:WidgetCollection".

8.Right click on "options" and create node "option1" , add properties to the node "text" and "value" with       the data required,create required number of options(option2,option3...) Our component is created.

9.We can drag this component in the page.But by default our component will not be displayed in the side        kick.To make the component visible in side kick ,select the design mode from side kick .Now click on the edit button available on the "parsys" component of the page and enable the component or component group (Group: MyComponents) by selecting the checkbox.
Now we can drag the component on to the page.

You can display the selected value by adding the line "<%=properties.get("checkboxtext",String[].class)%>" to the component jsp

You can download the code package here checkboxtest-1.0