Skip to Content
avatar image
Former Member

How to differentiate multiple requests attached to one oData model

Hello,

Looking for best practice / ideas on how to structure our app to handle multiple attachRequestSent / attachRequestCompleted events to the same oData Model.  On one particular page I have a tab control with each tab having a table which is bound to a separate HANA calculated view within the same .xsodata file.

The issue is that the attachRequestCompleted cannot differentiate (as far as I can tell) which data is returned for the appropriate tab.  So, if I'm on say, Tab E, and the data for Tab A returns, the attachRequestCompleted event fires for all tabs/tables, and the busyIndicator for the table on Tab E (and every other tab) stops/hides, even though the data for Tab E has not returned yet.

Moreover, if you navigate to another page within the application, subsequent data pulls on other pages using the same model now continue to trigger the attachRequestCompleted for each of the tabs on the original screen.

Is there a recommended way to setup specific listeners for separate events like these, or should we have a distinct data model for each tab, or...?

onMaterialChange: function(mtrlCode) {


       var materialFilter = [ui5.createTableFilter("MTRL", 'equals', mtrlCode, null)];
       oLEMTabsController.refreshInventoryGrid(materialFilter);
       oLEMTabsController.refreshProductionGrid(mtrlCode);
       oLEMTabsController.refreshBatchLvlInvnGrid(mtrlCode, oPlant);
       oLEMTabsController.refreshDistributionNetworkGrid(materialFilter);
       oLEMTabsController.refreshShipmentsGrid(mtrlCode);
       oLEMTabsController.refreshExceptionsGrid(mtrlCode);
       oLEMTabsController.refreshPMTsGrid(mtrlCode);
       oLEMTabsController.refreshSalesOrdersGrid(mtrlCode, oPlant);
       oLEMTabsController.refreshPMTIntransitGrid(mtrlCode);


},

refreshInventoryGrid: function (filter) {


       var oTableInventory = utilities.getControlFromUI("tblInventory");
       oTableInventory.setThreshold(10);
       oTableInventory.setBusyIndicatorDelay(0);
       oTableInventory.bindRows({
            path: "/TAB_INVN",
            filters: filter
       }).rerender();


       oDataModel.attachRequestSent(function (oEvent) {
            oTableInventory.setBusy(true);
       });
       oDataModel.attachRequestCompleted(function (oEvent) {
            oTableInventory.setBusy(false);
       });
       oDataModel.attachRequestFailed(function (oEvent) {
            oTableInventory.setBusy(false);
       });
},

refreshProductionGrid: function (code) {


       if (code){
            oLEMTabsController.refreshGrid("tblProduction", "/TAB_PRODNParameters(IN_MTRL='"+code+"')/Results");
       }
},


[and so on...]

refreshGrid: function(tableId, oPath){
      var oTable = utilities.getControlFromUI(tableId);
      oTable.setThreshold(100);
      oTable.setBusyIndicatorDelay(0);
      oTable.bindRows({
           path: oPath
      }).rerender();


      oDataModel.attachRequestSent(function (oEvent) {
            oTable.setBusy(true);
      });
      oDataModel.attachRequestCompleted(function (oEvent) {
            oTable.setBusy(false);
      });
      oDataModel.attachRequestFailed(function (oEvent) {
            oTable.setBusy(false);
      });
},
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Jan 13, 2015 at 11:15 PM

    One way could be to keep track of the URLs used for the request. There is a lot of information coming back in the "oEvent" parameter you are not using in the callbacks:

    {string}                                    oControlEvent.getParameters.url           The url which was sent to the backend
    

    Reference - OpenUI5 SDK - Demo Kit

    It does seem wrong though. Have you explored various binding techniques for your table controls? Usually changing the binding automatically reloads and does the necessary wait timers etc.

    Oli

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Sandip Agarwalla

      Actually, I think it wasn't doing quite what I described in my reply above.  I was still attaching the attachRequestSent event to the model, but listening for the the dataReceived on the table binding, like this:

      oDataModel.attachRequestSent(function (oEvent) {
             oTableInventory.setBusy(true);
        });
        oTableInventory.getBinding().attachDataReceived(function(oEvent){
             oTableInventory.setBusy(false);
        });
        oDataModel.attachRequestFailed(function (oEvent) {
             oTableInventory.setBusy(false);
        });
      

      So when I clicked on another tab which kicked off a separate data retrieval, it was setting the inventory tab to busy based on the attachRequestSent event for the shared model, and never hitting the tablel binding's attachDataReceived again.  Really what was needed, and seems to be working, is this:

        oTableInventory.getBinding().attachDataRequested(function(oEvent){
             oTableInventory.setBusy(true);
        });
        oTableInventory.getBinding().attachDataReceived(function(oEvent){
             oTableInventory.setBusy(false);
        });
        oDataModel.attachRequestFailed(function (oEvent) {
             oTableInventory.setBusy(false);
        });
      

      Thanks everyone for your help.