Closed apazureck closed 7 years ago
Hello!
Isn't it called "binding" inside an XML view, e.g. <form:SimpleForm binding="{myodatamodel>/MyItems(1)}">?! But "bindElement" in JavaScript should be OK.
It's hard to tell what goes wrong here from the given information. Basically, that's how it should work and how we use it ourselves in some examples.
Is there an easy way for you to share more information, e.g. complete files?
Best regards, Thomas
Hi,
I neither used the XML binding syntax nor did I use ODataV4 binding mechanism, but the (usual) Element.bindElement syntax is without curly braces:
view.byId("myform").bindElement("myodatamodel>/MyItems(1)");
Can the ODataV4 developer guide be wrong in this regards?
(I also found this example page which indicates that the XML syntax is with curly braces and should be therefore correct (as Thomas mentioned with attribute "binding" instead of "bind"): https://openui5.hana.ondemand.com/#docs/guide/91f05e8b6f4d1014b6dd926db0e91070.html)
SeeSharpSoft is right, of course. You can call bindElement in two ways, with a simple string or with a parameters object. In both cases, the path is just a path without curly braces.
In contrast, the "binding" attribute in an XML view uses binding syntax with curly braces.
@ThomasChadzelek & @SeeSharpSoft: Sorry, you are right of course. It is called binding. This was a typo. At last I was not sure, which syntax was correct, as neither of them worked :)
Ok, let me rephrase my question here. Would it be possible to get some more extended examples on the odata topic. As I understand it and my colleagues told me, odata is the recommended way to go (odata v2 at least). SAP working on the standards on odata together with MS second that.
Sadly I am not allowed to publish any code, as it is from my employer. I will try to make an example service these days. I just hoped somebody had a similar issue with the binding.
Here some description, what were my steps:
ListA
), which are published by my odata service (ASP.NET - odata v4). These Items have a reference (key only) to another entity set (ListB
) on my service. They have both a Name
property, which is a text."ams"
) in my manifest.json
.sap.m.Table
(items
). <Table items="{ams>/ListA}" select="onSelectionChange">...</Table>
.setBindingContext(selectedItemData, "ams");
of my detail view.sap.m.Text
elements to display the data of the selected Item of ListA
, which works just fine: <Text text="{ams>Name}"/>
What I wanted to do next ist something like that:
<Text binding="{ams>/ListB(1)}" text="{ams>Name}"/>
or
<Panel binding="{ams>/ListB(1)}"><Text text="{ams>Name}"/>...(further Text)...</Panel>
So I expected to get the name of the first item in ListB
Later I wanted to change that 1
to an expression binding, which should look something like that:
{= {ams>ItemBId}}
, to get the reference in my first item.
So my question here is: Can you tell me, how to bind such a thing correctly? A possible scenario would be to use this, if you have two odata services or another model. There you cannot use $expand. In my case I just looked for a quick work around, as i did not want to change the odata service.
Thank you and best regards
Here's what one of my colleagues has to say about this.
Usually, one would use a navigation property here instead of having the key properties of ListB repeated in ListA. If the service however does not use a navigation property and cannot be changed you have to set the binding of the Panel to display the ListB entity corresponding to the selected ListA entity in onSelectionChange:
In the xml view, add an id to the panel control so that you can access it in controller coding
<Panel id=“myPanel“>
In controller coding, add sap/ui/model/ODataUtils to the imported modules as ODataUtils
onSelectionChange : function (oEvent) {
var sItemBId = oEvent.getParameters().listItem.getBindingContext().getProperty(“ItemBId”);
// Note: the call to ODataUtils should only be done if the itemBId has the OData type Edm.String
// for all other types, take the value as is;
// calling ODataUtils.formatValue would then even be wrong as it formats literals according to the
// OData V2 standard
this.getView().byId(“myPanel”).bindElement(
“/ListB(“ + ODataUtils.formatValue(sItemBId, "Edm.String") + “)”);
}
If this does not help, please provide more details on what goes wrong, e.g. console log, requests you see in network tab, errors thrown, ...?
Hi,
Thank you for your support. I just wanted to give you feedback, that I am currently not on this issue. Sorry. I solved it using navigation properties. But I think I had a misconception on where the binding on the odata model ends (and therefore the request sent to the serivce) and the "local" binding expression on the received data starts.
But as I stated earlier: It would be great, if you could provide some tutorial on this issue, as the current information on this topic is really hard to get as a newbie to ui5.
And having two odata services on one application (may be not Fiori conform) is not an exceptional issue, I guess. And I if you do not own the odata service it would be nice to have a little more light on how to combine the data from different sources.
Cheers
OpenUI5 version: 1.40.6
Browser/version (+device/version): ie/chrome/firefox
Steps to reproduce the problem:
binding=myodatamodel>/MyItems(1)}"
, or in codebehind with an onInit Method:.byId("myform").bindElement("myodatamodel>/MyItems(1)");
<Text text="{myodatamodel>ItemName}"/>
)What is the expected result? The text field in the form should display the Item name.
What happens instead? It trys to append the ItemName binding to the odata Request:
http://myodataservice.com:8000/myservice.svc/MyItems(1)/ItemName
I read the information here: https://openui5.hana.ondemand.com/#docs/guide/54e0ddf695af4a6c978472cecb01c64d.html
It told me it is possible this way, but it is not, obviously. What is going wrong here or am not getting something right?
EDIT: