0
votes

I am trying to display an odata property of edm.time type in an UI5 form input field . View code

      <Input id="id1" placeholder="Enter value" value="{ path: 'START_TIME', mode: 'sap.ui.model.BindingMode.OneWay' }" width="500%" editable="false"/>

START_TIME is a property of the entity

Controller code-

    onInit: function () {
         var model= new sap.ui.model.odata.v2.ODataModel("<xsodata url>");
         model.setDefaultBindingMode(sap.ui.model.BindingMode.TwoWay);
         this.getView().setModel(model);
         var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
         oRouter.getRoute("<pattern_name>").attachMatched(this._onObjectMatched, this);

    },
    _onObjectMatched: function (oEvent) {
        var oArgs, oView;
        oArgs = oEvent.getParameter("arguments");
        oView = this.getView();
        oView.bindElement({
             path : "/" + oArgs.objPath
        });

     }

Here object path is as follows-
    /Entityname/<id of a partcular item in that entity>

When I am trying to show the start time property in the view, it returns object object.I need the time in string format.I have already used formatter for the same in a table and it works fine.But there the aggregation items binding was different because it was a table control.I need the value in input field in UI5 form Please help

1

1 Answers

1
votes

The binding path syntax should be

/EntitySet('id')    //In case of a string id
/EntitySet(id)      //In case of a number id

Also a double // at the beginning is not supported. Please check if the "/" + is needed.

The OData Edm.Time can be formatted with a sap.ui.model.odata.type.Time type:

 <Input id="id1" placeholder="Enter value" value="{ path: 'START_TIME', mode: 'sap.ui.model.BindingMode.OneWay', type: 'sap.ui.model.odata.type.Time' }" width="500%" editable="false"/>

You can provide further format options to customize the output:

 <Input id="id1" placeholder="Enter value" value="{ path: 'START_TIME', mode: 'sap.ui.model.BindingMode.OneWay', type: 'sap.ui.model.odata.type.Time', formatOptions: {style: 'short'} }" width="500%" editable="false"/>

Types (compared to formatters) support input and output conversion. So they can be used in a two-way bound input without additional coding.