cancel
Showing results for 
Search instead for 
Did you mean: 

Calling firePropertiesChanged on load fail

Former Member
0 Kudos

Hi all,

I am trying to get some information of a result set in the shape of a component. The functionality is provided by the excellent Community Package, see: https://github.com/org-scn-design-studio-community, however, I do not want to overload my users with all of the components provided by it. On top of that I believe the code needed to get the functionality we need could be quite little.

The problem I face has to do with what seems to be the internal caching mechanism DS components have between the client run-time environment and the JS logic that is executed on the server.

When I update the data property, I want to make sure that the client side is aware that the number of rows now has been updated as well. However I am unable to do that. It just keeps showing the default value.


Can anybody tell me how the firePropertiesChanged method is supposed to work? And what is going wrong here?


See the code to the component attached. I am using DS15SP2.


Kind regards,

Attila


//var ResultSetInfo = function () {

sap.designstudio.sdk.Component.subclass("blah.ResultSetInfo", function() {

  var _data;

  var _numberOfRows;

    this.init = function () {

    console.log("init");

    }

    this.beforeUpdate = function () {

    console.log("beforeUpdate called _numberOfRows var", _numberOfRows);

    };

    this.afterUpdate = function () {

    console.log("afterUpdate called _numberOfRows var", _numberOfRows);

    };

    this.data = function (value) {

    console.log("data (g/s)etter arg", value);

  

        if (value === undefined) {

            return _data;

        } else {

            _data = value;

            return this;

        }

    };

   

    this.resetInfo = function(value) {

    console.log("resetInfo arg", JSON.stringify(value), "resetting the numberOfRows and firing changes");

  

    _numberOfRows = _data["axis_rows"].length;

    this.firePropertiesChanged(["numberOfRows"]);

    }

    this.numberOfRows = function (value) {

    console.log("numberOfRows (g/s)etter arg", JSON.stringify(value));

  

    if (value === undefined) {

    return _numberOfRows;

    } else if (value === "<reset>"){

    // Does not work. It seems we need to still try the firePropertiesChanged method. Yet that does not work.

    _numberOfRows = _data["axis_rows"].length;

    return this;

    } else {

    _numberOfRows = value;

    return this;

    }

    };

// INDEPENDENTDEVELOPMENT:

//};

});


<?xml version="1.0" encoding="UTF-8"?>

<sdkExtension

  xmlns="http://www.sap.com/bi/zen/sdk"

  title="ResultSetInfo"

  version="1.0"

  vendor="Blah"

  id="blah.resultsetinfo">

  <component

  databound="true"

  icon="res/icon.png"

  id="ResultSetInfo"

  handlerType="div"

  title="ResultSetInfo">

  <jsInclude>res/js/component.js</jsInclude>

  <property id="data" title="Data Series" type="ResultSet" group="DataBinding"/>

  <property id="resetInfo" title="For resetting the info" type="String" group="Display" visible="false"/>

  <property id="numberOfRows" title="Number of rows" type="int" group="Display" visible="false"/>

  <initialization>

  </initialization>

  </component>

</sdkExtension>


class blah.ResultSetInfo extends Component {

  int getNumberOfRows() {*

  this.resetInfo = Math.random();

  return this.numberOfRows;

  *}

}

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Attila,

One quick question .Why do you need this.resultInfo() ? you can use afterUpdate() for updating the getter&setter . i just re-ordered the code. Hope this might help.


sap.designstudio.sdk.Component.subclass("blah.ResultSetInfo", function() {

  var _data; 

   var _numberOfRows; 

     this.init = function () { 

     console.log("init"); 

     } 

     this.beforeUpdate = function () { 

     console.log("beforeUpdate called _numberOfRows var", _numberOfRows); 

     }; 

     this.afterUpdate = function () { 

    

     _numberOfRows = _data["axis_rows"].length; 

     this.firePropertiesChanged(["numberOfRows"]); 

     console.log("afterUpdate called _numberOfRows var", _numberOfRows); 

     }; 

     this.data = function (value) { 

     console.log("data (g/s)etter arg", value); 

     

         if (value === undefined) { 

             return _data; 

         } else { 

             _data = value; 

             return this; 

         } 

     }; 

      

     this.resetInfo = function(value) { 

     console.log("resetInfo arg", JSON.stringify(value), "resetting the numberOfRows and firing changes"); 

     

    

     } 

     this.numberOfRows = function (value) { 

     console.log("numberOfRows (g/s)etter arg", JSON.stringify(value)); 

     

     if (value === undefined) { 

     return _numberOfRows; 

     } else if (value === "<reset>"){ 

     // Does not work. It seems we need to still try the firePropertiesChanged method. Yet that does not work. 

     _numberOfRows = _data["axis_rows"].length; 

     return this; 

     } else { 

     _numberOfRows = value; 

     return this; 

     } 

     }; 

  // INDEPENDENTDEVELOPMENT: 

  //}; 

  }); 

And to answer your question firePropertiesChanged is used to update values .the changesyou made in component.js/additonal-prop.js  will get updated in component.js/additional-prop.js/contribution.ZTL .


Thanks

Naveen.


firePropertiesChanged

Former Member
0 Kudos

Hi Naveen,

Awesome! Thank you for your answers. Indeed updating the numberOfRows property in the afterUpdate method does indeed work like a charm. Thanks for your explanation on the firePropertiesChanged, this is what I gathered but I was apparently using it in the wrong place. The resetInfo method was there to try to force the runtime environment to reach out to the server side state to get the latest value of numberOfRows - it was not working. Luckily it now is no longer needed. Using you suggestions, I can now achieve the simple code I had in mind:


var _data;

var _numberOfRows;

this.afterUpdate = function() {

    _numberOfRows = _data["axis_rows"].length;

    this.firePropertiesChanged([ "numberOfRows" ]);

};

this.data = function(value) {

    console.log("data (g/s)etter arg", value);

    if (value === undefined) {

        return _data;

    } else {

        _data = value;

        return this;

    }

};

this.numberOfRows = function(value) {

    if (value === undefined) {

        return _numberOfRows;

    } else {

        _numberOfRows = value;

        return this;

    }

};

Former Member
0 Kudos

Hi Attila ,

Am glad it worked

Basically the afterUpdate() will trigger when any setter get updated or modified. so use afterUpdate() for the updating the setter .

Thanks

Naveen

Answers (0)