Reputation: 2497
I have the following CQ dialog example:
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root
jcr:primaryType="cq:Dialog"
height="{Long}550"
title="my Dialog"
xtype="dialog">
<items
jcr:primaryType="cq:Widget"
xtype="tabpanel">
<items jcr:primaryType="cq:WidgetCollection">
<info
jcr:primaryType="cq:Panel"
id="infoTab"
title="-Info">
<items jcr:primaryType="cq:WidgetCollection">
<info
jcr:primaryType="cq:Widget"
id="info"
title="Info"
xtype="dialogfieldset">
<items jcr:primaryType="cq:WidgetCollection">
<service
jcr:primaryType="cq:Widget"
fieldLabel="Info"
name="./bp_info"
type="select"
xtype="selection"/>
</items>
</info>
</items>
</info>
</items>
</items>
</jcr:root>
In my java Servlet class I can access this dialog as follows:
private void createJsonObj(Node rootNode){
Node infoNode = rootNode.getNode("dialog");
}
infoNode
contains all elements and their properties as far as well.
My question is: How can I store the elements of this dialog in a json format, so that I can easily recover this dialog in some javascript from the created jsonObject?
Upvotes: 0
Views: 2029
Reputation: 9281
You need not store the elements in a json format in your servlet to access it in javascript, the path of the dialog is sufficient.
One way through which you can get the dialog object is by using the getDialog() method of CQ.WCM class (as shown below). This would return a CQ.Dialog object which can be manipulated based on your requirements.
var dlg = CQ.WCM.getDialog(dialogPath);
You can also make an AJAX GET request to the dialog path with the selector ".inifinity.json" to get the dialog in the json format. For example:
var url = CQ.HTTP.externalize(dialogPath + ".infinity.json");
var dlg = CQ.HTTP.eval(url);
For reference, you can check the docs
Upvotes: 2