0
votes

In my SAPUI5 app I'm using odata v4 model to communicate with the server. I have a detail view that binds to an existing object something like this:

// Controller code:
this.getView().bindElement({
                    path: "/Objects(" + this.m_ObjectId + ")",
                    model: "modelName"
                });

If I want to create a new item in that view instead, I'm not binding to an existing item of course. From the documentation I saw that one should create new items like this:

var oModel = this.getModel("modelName");
var oListBinding = oModel.bindList('/Objects');
var oNewKap = oListBinding.create({
    'OBJECT_ID': 0,
    'SOME_PROP': 'Test'
});

The question now his, how to bind that newly created (transient) object to my view? If I do a

this.getView().bindElement({
                        path: "/Objects(0)",
                        model: "modelName"
                    });

The app will try to fetch an existing item from the server again...

Any help is appreciated!

1
Hmm, anyone willing to name a reasing for downvoting?Alexander Bartz
Did you try without providing an ID so that the framework can generate a temp one? It was 'createEntry' in v2.ODataModel... Not too familiar with v4. Kind of weird that the create method only exists on ListBinding :/cschuff
Thx! After all what I've tried I'm not sure if I did test without id. I'll try next week, since I have no chance at the moment to access that code. And yes: oData v4 support is really confusing.I'll keep this updated.Alexander Bartz
How do you create a new item from a page which displays details of an existing item? From a UX aspect, I don't see how this makes sense.Chris Neve
I'm using routing with value ID=0 from anywhere in the application (or even as entry page if needed). The detail page then should handle the creation of the new item.Alexander Bartz

1 Answers

0
votes

You may do this.getView().setBindingContext(oNewKap)