Saturday 6 September 2014

CQ Component Dialog

<?xml version="1.0" encoding="UTF-8"?> <jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" jcr:primaryType="cq:Dialog" activeTab="0" title="Component Title" xtype="tabpanel"> <items jcr:primaryType="cq:WidgetCollection"> <tab1 jcr:primaryType="cq:Widget" title="Tab 1" xtype="panel"> <items jcr:primaryType="cq:WidgetCollection"> <checkbox jcr:primaryType="cq:Widget" fieldLabel="Checkbox" fieldDescription="" defaultValue="false" inputValue="true" name="./checkbox" type="checkbox" xtype="selection"/> <cqinclude jcr:primaryType="cq:Widget" path="/path/to/other/dialog/inputs.infinity.json" xtype="cqinclude"/> <datetime jcr:primaryType="cq:Widget" fieldLabel="Date Time" fieldDescription="" name="./dateTime" allowBlank="{Boolean}true" xtype="datetime"/> <dialogfieldset jcr:primaryType="cq:Widget" collapsed="{Boolean}true" collapsible="{Boolean}true" title="Fieldset Title" xtype="dialogfieldset"> <items jcr:primaryType="cq:WidgetCollection"> </items> </dialogfieldset> <displayfield jcr:primaryType="cq:Widget" ignoreData="{Boolean}true" hideLabel="{Boolean}true" hidden="{Boolean}false" value="Escaped HTML or plain-text to display" xtype="displayfield"/> <dropdown jcr:primaryType="cq:Widget" fieldLabel="Dropdown" fieldDescription="" defaultValue="" name="./dropdown" type="select" xtype="selection"> <options jcr:primaryType="cq:WidgetCollection"> <children jcr:primaryType="nt:unstructured" text="Option 1" value="option1"/> <descendants jcr:primaryType="nt:unstructured" text="Option 2" value="option2"/> </options> </dropdown> <html5smartfile jcr:primaryType="cq:Widget" autoUploadDelay="1" ddGroups="[media]" fieldLabel="HTML 5 Smart File" fieldDescription="" fileNameParameter="./fileName" fileReferenceParameter="./fileReference" name="./file" xtype="html5smartfile"/> <inlinetextfield jcr:primaryType="cq:Widget" fieldLabel="Inline Text Field" fieldDescription="" name="./inlineTextField" regex="(.*)" regexText="Message If Regex Fails" xtype="inlinetextfield"/> <ownerdraw jcr:primaryType="cq:Widget" fieldLabel="Owner Draw" fieldDescription="" html="HTML fragment to use as the owner draw's body content" name="./ownerDraw" url="The URL to retrieve the HTML code from. Replaces HTML defined in html." xtype="ownerdraw"/> <paragraphreference jcr:primaryType="cq:Widget" fieldLabel="Paragraph Reference" fieldDescription="" name="./paragraphReference" regex="(.*)" regexText="Message If Regex Fails" xtype="paragraphreference"/> <multifield jcr:primaryType="cq:Widget" fieldLabel="Multifield" fieldDescription="Click the '+' to add a new page" name="./multifield" xtype="multifield"> <fieldConfig jcr:primaryType="cq:Widget" width="155" xtype="pathfield"/> </multifield> <pathfield jcr:primaryType="cq:Widget" fieldLabel="Pathfield" fieldDescription="Drop files or pages from the Content Finder" name="./pathfield" regex="(.*)" regexText="Message If Regex Fails" rootPath="/content" suffix=".html" showTitlesInTree="{Boolean}true" typeAhead="{Boolean}true" xtype="pathfield"/> <radiobuttons jcr:primaryType="cq:Widget" fieldLabel="Radio button" fieldDescription="Field Description" name="./radioButton defaultValue="option1" type="radio" xtype="selection"> <options jcr:primaryType="cq:WidgetCollection"> <option1 jcr:primaryType="nt:unstructured" text="Option 1" value="option1"/> <option2 jcr:primaryType="nt:unstructured" text="Option 2" value="option2"/> </options> </radiobuttons> <resType jcr:primaryType="cq:Widget" ignoreData="{Boolean}true" name="./sling:resourceType" value="some/resource/type" xtype="hidden"/> <richtext jcr:primaryType="cq:Widget" fieldLabel="Rich Text" fieldDescription="" defaultValue="" hideLabel="{Boolean}true" name="./richText" xtype="richtext"> <rtePlugins jcr:primaryType="nt:unstructured"> <table jcr:primaryType="nt:unstructured" features="*"/> </rtePlugins> </richtext> <searchfield jcr:primaryType="cq:Widget" fieldDescription="" fieldLabel="Search Field" name="./searchField" regex="(.*)" regexText="Message If Regex Fails" url="The URL where the search request is sent to (defaults to "/content.search.json")" xtype="searchfield"/> <sizefield jcr:primaryType="cq:Widget" fieldLabel="Sizefield" fieldDescription="" heightParameter="./height" widthParameter="./width" heightSuffix="px" widthSuffix="px" xtype="sizefield"/> <textarea jcr:primaryType="cq:Widget" fieldLabel="Textarea" name="./textarea" grow="{Boolean}true" regex="(.*)" regexText="Message If Regex Fails" xtype="textarea"/> <textfield jcr:primaryType="cq:Widget" fieldLabel="Textfield" name="./textfield" xtype="textfield"/> </items> </tab1> <tab2 jcr:primaryType="cq:Widget" cropParameter="./image/imageCrop" ddGroups="[media]" fileNameParameter="./image/fileName" fileReferenceParameter="./image/fileReference" mapParameter="./image/imageMap" name="./image/file" requestSuffix="/image.img.png" rotateParameter="./image/imageRotate" sizeLimit="100" title="Image" xtype="html5smartimage"/> </items> </jcr:root>

OSGi Service Declaration

@Component( label = "Service name", description = "Service description", metatype = true, immediate = false) @Properties({ @Property( label = "Vendor", name = Constants.SERVICE_VENDOR, value = "Customer", propertyPrivate = true ) }) @Service public class SampleServiceImpl implements SampleService { private final Logger log = LoggerFactory.getLogger(this.getClass()); /** * OSGi Properties * */ private static final boolean DEFAULT_SAMPLE = false; private boolean enabled = DEFAULT_SAMPLE; @Property(label = "Prop name", description = "Prop description", boolValue = DEFAULT_SAMPLE) public static final String PROP_SAMPLE = "prop.sample"; ... @Activate protected void activate(final Map<String, String> config) { } @Deactivate protected void deactivate(final Map<String, String> config) { } }

How to define Sling Servlet?

Sling Servlet annotations

Configurations methodsresourceTypesselectorsextensions are IGNORED if paths is set.
Methods defaults to GET if not specified.

@SlingServlet( label = "Samples - Sling Servlet", description = "...", paths = {"/services/all-sample"}, methods = {"GET", "POST"}, resourceTypes = {}, selectors = {"print.a4"}, extensions = {"html", "htm"} )

Safe Methods Servlet (GET, HEAD)

public class SampleServlet extends SlingSafeMethodsServlet implements OptingServlet { ... }

All Methods Servlet (GET, HEAD, POST, PUT, DELETE)

public class SampleServlet extends SlingAllMethodsServlet implements OptingServlet { ... }

How to start workflow programmatically?

Start Workflow programmatically

@Reference WorkflowService wfService; ... WorkflowSession wfSession = wfService.getWorkflowSession(jcrSession); WorkflowModel model = wfSession.getModel("/etc/workflow/models/x/jcr:content/model"); WorkflowData data = wfSession.newWorkflowData("JCR_PATH", payloadPath); Workflow workflow = wfSession.startWorkflow(model, data);


Difference between Dialog & Design dialog in CQ


Design Dialog:  It is used to globally store variables throughout  the template properties.

Dialog:  Stores all variables inside the page’s properties


One of the major benefits of using the design dialog is that if you have a hundred pages sharing the same template the variables will be shared amongst them. Also, note that you can have both design dialog and normal dialog on a page.
A dialog saves content relative to the given page.  In comparison, a 'design' dialog saves content globally (at a template level).

How to reuse existing dialog elements into other component's dialog?

How is it possible to reuse existing dialog elements such as tabs in other dialogs?

For this use-case, a specific widget with the label cqinclude exists which allows for inclusion of existing dialog elements in other dialog definitions. The generic JSON format is used on the client side to construct the actual dialog.
Following is an example which uses the cqinclude widget to include an existing tab from an existing dialog:
{
  "jcr:primaryType": "cq:Widget",
  "xtype": "cqinclude",
  "path": "/libs/replication/components/agent/tab_extended.infinity.json"
}
The path property needs to point to a dialog-resource that is to be included in JSON format.
The above example was taken from the reverse-replication agent component (please refer to the/libs/replication/components/revagent node).