on 09-24-2014 11:32 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
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
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.