AEM DefaultValue recorded in JCR

I noticed that when I set my defaultValue for the dropdown, altho it is correctly selected in the dropdown, when I first add my component to the page, it does not write the defaultValue to the appropriate JCR until I edit the component and save it. Even if I just open the appropriate dialog and click OK, now my component works as expected because the values โ€‹โ€‹were added to the JCR.

I'm sure there is an important part I'm missing here, does anyone know how the defaultValues โ€‹โ€‹needed to render the component correctly can be added to the JCR when they are first added to the page?

+3


source to share


3 answers


As Schwan says, this is how it works. The defaults or empty texts are for dialog only. They are not saved until the dialog is created. Properties must be set by another method. CQ already comes with this feature and you can do it without any custom code.

Under your component, create a node cq: template [nt: unstructured]. If all data is stored directly on the component node, add the default values โ€‹โ€‹as properties in the cq: template node with the same name as in your dialog box. If the data is stored in a child node, add a similar node to the cq: template node.



Source: http://blogs.adobe.com/experiencedelivers/experience-management/defaults-in-your-component/

+6


source


I believe this is just the way it works. The default value given in the dialog is not used until the dialog is loaded / saved, so until that happens, the node in the JCR repository that is the author will not have a default value.

We got around this in the project by adding an end code that was attached to the component (tag) so that when the component was loaded, if the property didn't exist, it would be written by default first time. Example:



if (wcmMode == WCMMode.EDIT )
{
   if(!currentNode.hasProperty("SomePropertyThatWillAlwaysExistIfTheDialogHasBeenSaved")) {
         currentNode.setProperty("PropertyThatShouldHaveDefault", GlobalConstants.TRUE);
         currentNode.getSession().save();
   }
}

      

+4


source


Like Sharat Madappa, it is said to work great if the component name and jsp name are the same. If you don't have a name.jsp component underneath the component or page, the cq: template won't work. (Link: http://labs.6dglobal.com/blog/2014-07-08/using-the-cq-template/ )

If you hava componentname.html under your component, change the node type [cq: template] to [cq: Template] instead of [nt: unstructured]. In this case, the defaultValues โ€‹โ€‹can be added to the JCR when they are first added to the page.

+1


source







All Articles