cancel
Showing results for 
Search instead for 
Did you mean: 

SAP UI5 OData model: Replace Object binding or update reference

0 Kudos

Hello,

We have a UI5 application utilizing a OData Model V2 (SAP Gateway) two-way binding, quite straight forward I'd say.

I think I understand the view binding and retrieving the bound context within event handlers. But I can't wrap my head around updating a reference/object. I have a single record bound to a view displaying the data in a form. Some properties are reference via 'expand' (UI5 binding) using the NavigationProperty (Gateway/OData).

Pseudo-Binding like:

<Input binding="{model>/user('ernie')}" value="{model>name}" />
<Text binding="{path: 'model>/user('ernie'), expand: 'NavUserDetails'}" '" text="{model>NavUserDetails/email}" />

The above is not actually there but it should illustrate that the bound context has a 1:1 navigation to another entity (UserDetails) which is displayed. Depending on the entered name the details are supposed to adjust (reload).

However the reload (correct display of Text element) only happens whenever I commit the updated Input (requires a db store). After the PUT request the UI5 model reloads the data from the backend.

Now my question is can I manually replace the object property (navigation) without commiting the name. I already have all the users loaded by the model - it is de-facto available in the model including the UserDetails entities. I want to avoid a commit, I simply want the user to be able to reset some fields and explicitly hit a save button whenever done.

What I tried is to set the Property in the event handler like

oContext = oControlEvent.getSource().getBindingContext("model");

//get User entity model>/User('bert')
var oUserEntity = oContext.getModel().getObject("model>/User('" +" oContext.getProperty("name") +"')" ) ;

//does not work - even if the return is true
oContext.getModel.setProperty("NavUserDetails", oUserEntity, oContext);

//does not work - even if the return is true
oContext.getModel().bindContext(oContext.getPath() +"/NavUserDetails", oUserEntity);

I also tried to set the property "NavUserDetails" with the context object of the user entity with no success. I already get the impression that this is not intended by the framework but maybe I just need a good hint.

thanks in advance

Accepted Solutions (0)

Answers (1)

Answers (1)

junwu
Active Contributor
0 Kudos
var oUserEntity = oContext.getModel().getObject("/User('" +" oContext.getProperty("name") +"')" ) ;

how about this?
0 Kudos

Hi Jun,

thanks but no, I know how to get the data content, but I want to replace the details property (which is an object ) of the current binding...

I think I might simply set the details manually like the email

oContext.getModel.setProperty("NavUserDetails/email", oUserEntity.email, oContext);

so the screen would fake to display the right details, however I's need to set he properties in a deferred group which I may not commit....

or simply use a JSON model as proxy 😞

best

Stefan