Suppose you have a included or a dragged and drop component on a page and you want the properties configured in the component dialog to be saved in the properties of the page ie jcrcontent as some other component also might want to use the same property.
Suppose it’s a drag
and drop component then the content hierarchy would be like
<page>/jcrcontent/par/<component>
Write
Now to save at jcrcontent level we need to move two levels up. So, in the component dialog the property ‘name’ should be
This will save the property at jcrcontent level.
Read
Now once you save the values and again open the component dialog it will not show the configured property value even though they are saved correctly. This is because we have only told the dialog where to save properties not from where to pick it. So by default its trying to pick from the component node itself.
For this we need a beforeloadcontent listener which is run before the dialog is loaded.
Listener node needs to be created below the xtype property node in the
dialog.
function(field, record, path) {
var targetField =
field.getName().replace('./', '');
var pathParts = path.split('/');
pathParts.pop(); //use this line to travel to hierarchy where you
original property has been set
pathParts.pop();
var jcrContentPath = pathParts.join('/');
// once you reach to that path in this case page jcr:content get the path
var response =
CQ.utils.HTTP.get(jcrContentPath + '.json'); // make get query to this path and
retrieve response
eval('var data =' + response.responseText);
//data will have all the property value associated
var originalPropName = "contentAuthors";
if (data[originalPropName] != undefined) {
var originalPropVal =
data[originalPropName];
this.setValue(originalPropVal);
//setting the value to corresponding component attribute
return false; //dont forget to return
false to set the value and stop further processing
}
}
Important to note in the listener is that we need pop as many times as the
level we need to move up. So here its 2. Also, take care of the property name.
Suppose it’s an included
component we can use property name as name="../contentAuthors"
and use the parthParts.pop() in listener only once.
how do i do the same thing in touch ui for aem6.3?
ReplyDelete