2 Replies Latest reply on Jul 17, 2013 6:16 AM by garth914

    Writing and reading value in widget to parent node




      CQ 5.6.1


      Using the Page's dialog, I have a property being written to and read from <current page>/jcr:content@isMenuRoot.


      I'd like to have another statically defined component on the page read and write to the same property on the page node.  It's easy enough to get the value written.  In this component's dialog, I set the name of the widget to "../isMenuRoot".  When I check the box and click OK, the expected attribute is written to the jcr:content node.  When I leave the box unchecked, the @isMenuRoot is removed.


      However, the saved value isn't being loaded when the dialog is invoked.  Hooking into the loadcontent event for the dialog simply doesn't show it in the record.  I've tried this with various xtypes and it makes no difference.


      I could have sworn I'd written and read values to parent nodes in older versions of CQ, but perhaps I'm remembering wrong.


      Does anyone know if I can load values written to a parent node from a component's dialog?




        • 1. Re: Writing and reading value in widget to parent node
          rush_pawan Level 4

          Hi Garth,


          Based on above scenario i would suggest you to write a event listener on field you want to display the value setup at page level.


          So looking at above requirement let's assume an exampleof a page and you are setting up a property "original" under "yourpage/jcr:content@original" and page has component/tab where you want to display this property value into one of the attribute say "componentproperty".


          To do that


          1. Create a listener node under the "componentproperty" node as nt:unstructured

          2. Create a listener event "beforeloadcontent" and set it with below function


          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

          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="original";


              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




          Above is just an example based on described scenario but you can tweak it as per your requirement because it all about travelling through path and processing the property value. Let me know if you need more information but i hope it will help you to proceed.




          • 2. Re: Writing and reading value in widget to parent node
            garth914 Level 1

            PERFECT!  I learn new things about CQ and ExtJS every day here.