cancel
Showing results for 
Search instead for 
Did you mean: 

OData binding with Associations

01-29-2014 11:58 AM
3587 views 6 comments Go to solution
0 Likes
SAP Managed Tags
Subscribe

Hi,

I've created a GW service structured with one main element and a few associations. These work fine in the browser:

  • /AssetCollection('1234')/ returns a single element
  • /AssetCollection('1234')/Stock returns a single associated element (with a 1...1 relationship defined in SEGW)
  • AssetCollection('1234')/AssetSummaryAlertSet returns an associated entity set (1...N)

I'm now trying to use these in my UI5 application. I set the application context to be (for example) /AssetCollection('1234') and can display elements of this entity using syntax like:


<Text text="{Id}"/>

I can also bind the associated entity collection to a List successfully using syntax:


<List headerText="Alerts" items="{AssetSummaryAlertSet}">

  <items>

    <ObjectListItem number="{Aoid}" title="{Title}">

      <attributes>

  <ObjectAttribute text="{Name}"/>

  <ObjectAttribute text="{Address}"/>

  </attributes>

    </ObjectListItem>

  </items>

</List>

My issue is displaying elements of associated entities where the relationship is 1..1:

I naively thought I could do something like:


<Text text="{StockCond/Quantity}"/>

This doesn't display anything and the corresponding endpoint is not called at all.

Looking at the binding in the Control Tree in the diagnostic popup tells me the path is: Stock/Quantity (invalid)

I get the same invalid error for my list however and that does display data!

Is this type of binding possible in UI5 or do I need to flatten my service and use something like $expand?

Thanks,

Gregor

0 Likes

Accepted Solutions (1)

Accepted Solutions (1)

qmacro
Developer Advocate
Developer Advocate
0 Likes

Just an inkling, but as an alternative to $expand, you might try an explicit binding specification on the Text control


<Text binding="Stock" text="Quantity" />

ISTR this should fire an OData call to fetch the associated entity, but I could be dreaming...

former_member182048
Active Contributor
0 Likes

Hi DJ

I think the following should work, the binding has to be relative to existing context

<Text binding="{/Stock}" text="{Quantity}" />


Couldnt get it working though see JS Bin


<commons:TextField  binding="{/Supplier}" value="{CompanyName}" />


should return


http://services.odata.org/V3/Northwind/Northwind.svc/Products(1)/Supplier/CompanyName


jsp

Former Member
0 Likes

Thanks John and DJ, I have been struggling with this one for hours!

I've ended up with

<Text binding="{StockCond}" text="{Quantity}" /> (dropping the leading / to make it relative rather than absolute path I think?)

I really appreciate the help. Your contributions to the UI5 community and beginners like myself are astonishing!

qmacro
Developer Advocate
Developer Advocate
0 Likes

Great, I was typing that XML in my reply while trying to do something else, and rushed it. Of course, the property bindings needed to go in {...} too, and I misread StockCond as Stock.

Note to self: do one thing at a time! 🙂

former_member182048
Active Contributor
0 Likes

cool, thanks

Answers (1)

Answers (1)

former_member182048
Active Contributor
0 Likes

Hi Gregor

Your on the right track, see JSBin HTML example, to expand try


{path:'/AssetCollection', parameters:{expand:'Stock'}}

hth

jsp