Skip to Content
0
Feb 18, 2016 at 04:59 PM

XML View and binding path

23 Views

Hello everyone

Within one single view I have a Text-element. This is to show the default customer number assigned to the logged in user in our ERP.

The data binding for it is set in the controller.

XML view:

<Text id="txtCustNo" text="{CustomerNo}"/>

controller:

var oText = oView.byId("txtCustNo");
oText.bindElement("/UserDefaultsSet('X')");

When testing it, the value in the Text-element shows up just fine.

So there is no issue with the gateway service implementation.

So far, so good, but...

I also need to populate a table with the list of sales organizations of this default customer number. This table is defined like that in the XML view:

mvc:View

<mvc:View
xmlns="sap.m"
xmlns:t="sap.ui.table"
...
<t:Table 
  id="tblCustSalesOrgs"
  navigationMode="Scrollbar" 
  noDataText="no data found" 
  selectionBehavior="Row" 
  selectionMode="Single">
  <t:columns>
  <t:Column id="col1">
  <Label text="Sales organization ID"/>
  <t:template>
  <Text text="{SalesOrgId}"/>
  </t:template>
  </t:Column>
  <t:Column id="col2">
  <Label text="Name"/>
  <t:template>
  <Text text=" {SalesOrgText}"/>
  </t:template>
  </t:Column>
  </t:columns>
</t:Table>
...

Now, in my OData model I have two entitysets available (CustomerSet and CustomerSalesOrgsSet) to populate this table. The implemented gateway services work fine when testing it using the SAP Gateway Client with e.g. /sap/opu/odata/sap/MYSERVICE/CustomerSet('0010074430')/CustomerSalesOrgsSet

But how to do the data binding for the table rows?

Adding a hardcoded binding path as rows attribute in aboves Table element of the XML view like that doesn't work:

rows="{/CustomerSet('0010074430')/CustomerSalesOrgsSet}"

Hard coding it like that in onAfterRendering event of the controller however works:

var oView = this.getView();
var oTable = oView.byId("tblCustSalesOrgs");
oTable.bindRows("/CustomerSet('0010074430')/CustomerSalesOrgsSet");

But how to put in the customer number (the one that came from /UserDefaults('X')/CustomerNo for the Text-element) dynamically into the binding path for my table rows?

I'd like to achieve this without any further user interaction as it is the views content that should show up initially and automatically.

Or is there a way to get the value of CustomerNo out of this /UserDefaults('X') context in the onAfterRendering event? I tried to do so but the data is not available at this point.

Thanks anyone for guiding me through this issue.

Regards, Renaud