cancel
Showing results for 
Search instead for 
Did you mean: 

OData aggregation binding & SAPUI5 XML views

Former Member
0 Kudos

Hi all,

I am trying to develop an SAPUI5 application. I am building on an existing application that was realized using XML views (instead of JS). Currently I am trying to solve the following problem.

I want to display the name of a specific partner (i,e, a partner with a specific partner function) in the app. The backend does provide an OData model with the root model element "order". From there I can get a list of all partners via the association "partners".

Now if I was using a JS view, I would probably try to implement a manual filter for the partner function, get the first entry from the filtered list via element binding, and display the name attribute of that entry.

However, I couldn't find any examples on how to do this in an XML view. (What's more, XML views are a pain to debug...). Any ideas?

Cheers,

Markus

Accepted Solutions (1)

Accepted Solutions (1)

former_member189945
Contributor
0 Kudos

Hi Markus,

Is the data always in the same order. If it is, you can access partner list by index like this:


value="{/partners/0/partnerName}"

Otherwise you could implement a formatter function in the controller of your XMLView and loop over the partners to get the correct one:


value="{path : '/partners',formatter:'.formatPartner'}"

In controller:

formatPartner: function(partners) {

     // TODO

     return partnerName;

}

Regards,

Kimmo

Former Member
0 Kudos

Hi Kimmo,

thanks for the suggestions. Now I've tried them both but didn't succeed.

Trying the first idea, no value is rendered. For the second possibility, the controller method is called but the parameter value is undefined. It seems that the context is somehow not set.

Here's how I load the model

var url = getURL('/...ODATA_SRV/'); 
var dataModel = new sap.ui.model.odata.ODataModel(url); 
sap.ui.getCore().setModel(dataModel);

Here's (part of) the view definition

     <form:SimpleForm  id="AddressForm"

  minWidth="1024" >

  <core:Title text="Plant Location" />

  <Label text="Name"/>

  <Text text="{

              path:    '/Partners',

              formatter: '.formatPartner'

            }"

  </form:SimpleForm>

          
          

The controller is incomplete at the moment. I just added a breakpoint to it and checked the parameter.


formatPartner : function(partners) {

return "Test";

}

Any more suggestion son what I'm doing wrong?

Regards,

Markus

former_member189945
Contributor
0 Kudos

Do you have following set on your sapui5 bootstrap?


data-sap-ui-xx-bindingSyntax="complex"

Regards,

Kimmo

Former Member
0 Kudos

Yes, I do. (The complex binding syntax does already work for other, simpler bindings.)

former_member189945
Contributor
0 Kudos

Do you have any other Models set? If yes, try naming dataModel and bind with that name


path:    'modelName>/Partners'

Regards,

Kimmo

Former Member
0 Kudos

Yes, sorry to disappoint you again, but I tried that too.

Regards,

Markus

former_member189945
Contributor
0 Kudos

OK. Can you recheck your path '/order/Partners' for proper case and any misspellings. I don't any reason why it should not work in case the data is loaded properly into the model. Do you have any other elements bind to the same model on the same view? Do they work?

Regards,

Kimmo

Former Member
0 Kudos

Well I don't have any working bindings of the partners associatiion at the moment. But I do have a working aggregation binding of the Objects association (also seen in the screenshot fo teh OData service above). It looks like this:


<Table

     headerText="{i18n>LineItemTableHeader}"

     items="{Objects}" >

     <columns>

          <Column>

               <Label text = "Items" />

          </Column>

          ... more columns ...

     </columns>

     <ColumnListItem>

          <cells>

               <Text text="{ItemName}" />

               ... more text ...

          </cells>

     </ColumnListItem>

</Table>

So as you see, I'm using multiple models (the i18n model in line 2). And binding whole aggregations of the data model works too (even without specifiying the model name explicitly as it's bound to the core). I only have a problem accessing single entries in the ways that you suggested...

Regards,

Markus

former_member189945
Contributor
0 Kudos

Sorry Markus, I don't have any more ideas what could be wrong. If you get it working, please post your solution.

Regards,

Kimmo

0 Kudos

Hi Markus,

shouldn't the path be without slash in the beginning? Just like the way you are getting at the "Objects" data.

<Text text="{

              path:    'Partners',

              formatter: '.formatPartner'

}"

"Partners" doesn't seem to be the root for your data, but rather a dependent entity set like "Objects".

Did you get your problem solved and might you please share your solution?

Thank you!

Anja

Former Member
0 Kudos

Hi Anja,

the truth is that I don't know a real solution. I had to abandon the project for a while and after coming back to it and implementing it as suggested above it worked. I suspect that the system upgrade that had been installed in the meantime did solve the issue. Maybe it was caused by a rather outdated version of the SAPUI5 libraries.

So, problem solved. Thanks to all of you for your comments and ideas!.

Regards,

Markus

Answers (1)

Answers (1)

Former Member
0 Kudos

USING MVC METHODE BIND ODATA TO XML TABLE IN SAP UI5 - My Solution

MY .XSODATA FILE

service namespace "sap.hana.contact.service" {     "SYSTEM"."TEMPUPLOAD" as "FILE_UPLOAD_TABLE";    }

SNIPET FROM Controller.js file

service namespace "sap.hana.contact.service" {     "SYSTEM"."TEMPUPLOAD" as "FILE_UPLOAD_TABLE";    }

SNIPET FROM XML VIEW FILE

<Table  id="BatchTable"  headerText="{i18n>LineItemTableHeader}"
  items="{/FILE_UPLOAD_TABLE}"
  visibleRowCount= "10">
  <columns>  <Column>  <header><Label text="Company name" /></header>  </Column>  <Column>  <header><Label text="Website" /></header>  </Column>  <Column>  <header><Label text="Sector" /></header>  </Column>  <Column>  <header><Label text="Firstname" /></header>  </Column>  <Column>  <header><Label text="lastname" /></header>  </Column>  <Column>  <header><Label text="Position" /></header>  </Column>  <Column>  <header><Label text="Email" /></header>  </Column>  <Column>  <header><Label text="Phone" /></header>  </Column> 
 
  </columns>  <ColumnListItem  type="Navigation"  press="handleLineItemPress" >  <cells>  <Text text="{ID}"/>  <Text text="{COMPANY_WEBSITE}"/>  <Text text="{SECTOR}"/>  <Text text="{FIRSTNAME}"/>  <Text text="{LASTNAME}"/>  <Text text="{EMAIL_ADDRESS}"/>  <Text text="{PHONE}"/>  <Text text="{POSITION}"/> 
 
 
  </cells>  </ColumnListItem>  </Table>

Hope it save some one time as well as the Posts above

Thanks