2020 Aug 11 2:13 PM
So, I have an xml view, and a table with some columns in it. I do the odata connecting (V4) in the controller.js, and with the table id I bind the data to the sap.m.table. If I know right, odata binding will get the type of the data from the metadata, which is fine, but I get the following error all the time:
FormatException in property 'text' of 'Element sap.m.Text#idView1--text0-idView1--table0-0': Type 'sap.ui.model.odata.type.Raw' does not support formatting
Hint: single properties referenced in composite bindings and within binding expressions are automatically convertedinto the type of the bound control property, unless a different 'targetType' is specified. targetType:'any' may avoidthe conversion and lead to the expected behavior. -
No matter what the Edm type is (String or Int32)
In js view I can define the type I need, but in xml I can not find the right way.
There is my view.xml:
<core:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" xmlns:commons="sap.ui.commons" xmlns:table="sap.ui.table"
controllerName="sapodatawithxmlview.View" xmlns:html="http://www.w3.org/1999/xhtml">
<Shell>
<App>
<pages>
<Page id="page" title="{i18n>title}">
<content>
<Table noDataText="Drop column list items here and columns in the area above" id="table0" items="{/ac4ypersistentchildodata}">
<items>
<ColumnListItem type="Active" id="item0">
<cells>
<Text id="text0" text="{id}"/>
<Text id="text1" text="{name}"/>
<Text xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" id="text1_copy5" text="{createdAt}"/>
</cells>
</ColumnListItem>
</items>
<columns>
<Column id="column0">
<header>
<Label text="ID" id="label0"/>
</header>
</Column>
<Column xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" id="column0_copy">
<header>
<Label text="Name" id="label0_copy"/>
</header>
</Column>
<Column xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" id="column0_copy2">
<header>
<Label text="Registration Date" id="label0_copy2"/>
</header>
</Column>
</columns></Table>
</content>
</Page>
</pages>
</App>
</Shell>
</core:View>
and the controller onInit method:
onInit: function() {
var oModel = new sap.ui.model.odata.v4.ODataModel({
groupId: "$direct",
synchronizationMode: "None",
serviceUrl: "https://localhost:44315/odata/"
});
oModel.setDefaultBindingMode("OneWay");
var oTable = this.byId("table0");
oTable.setModel(oModel);
},
Thank you any help in advance!!!
2020 Aug 13 4:56 PM
That's right. The v4.ODataPropertyBinding adds a corresponding data type according to the EDM Type from the `$metadata` document. See https://stackoverflow.com/a/62884400/5846045.
Consequently, apply targetType: 'any' to those OData property binding infos to turn the automatic type determination off. E.g.:
<cells>
<Text text="{ path: 'id', targetType: 'any', formatter: '.format' }" />
<!-- ... -->
</cells>
format: function(value) {
const formattedValue = /*Do something with the fn parameter(s)*/;
return formattedValue;
},
As shown above, you can optionally add a custom formatter to the controller to display the value correctly in the UI.
2020 Aug 13 4:56 PM
That's right. The v4.ODataPropertyBinding adds a corresponding data type according to the EDM Type from the `$metadata` document. See https://stackoverflow.com/a/62884400/5846045.
Consequently, apply targetType: 'any' to those OData property binding infos to turn the automatic type determination off. E.g.:
<cells>
<Text text="{ path: 'id', targetType: 'any', formatter: '.format' }" />
<!-- ... -->
</cells>
format: function(value) {
const formattedValue = /*Do something with the fn parameter(s)*/;
return formattedValue;
},
As shown above, you can optionally add a custom formatter to the controller to display the value correctly in the UI.