New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
odatamodel v4 - having a hard time to manipulate the data (doc bug) #2766
Comments
Hi @wernerdaehn , how to modify data in controller code is described in https://sapui5.hana.ondemand.com//#/topic/17b30ac2d5474078be31e695e97450cc.html. Does this help? As to your enhancements:
Enhancement 2: How should this work? The list binding would contain the additional default row? And this one would exist only on the client? Best regards |
Thanks Mathias, that changes a lot. When I read "binding" I interpreted that as "Control-to-Model Binding". It seems the term is used for "data-to-odatamodel binding" as well. Okay, understood. At least the things I'd like to do are possible. Then the enhancements are just to make life easier. Regarding the Enhancement 1, parameters within filters, this was asked quite often in stack overflow. That proofs I am not the only one. How would you build a master-detail screen using oData? A table at the top half allowing you to browse through the order header table. And a second table at the bottom showing the currently selected order's line items? I can think of a single solution only and that is the $expand, but that requires the odata service to be prepared for that. That does not need to be that case always. Then you have to synchronize the master/detail oData models somehow. Regarding Enhancement 2, the default row, this is again something very common. Most combobox controls or dropdown boxes are used as value help, showing all possible values for this field. Plus the option to specify NULL. For example the screen to enter a material has a drop down box for the material type and shows the allowed values only: Raw Material, Replenishable good,... or NULL. |
Hi Werner, yes, with the V4 Model the binding object is used for more than the binding of model and control. As for master-detail: The idea is to use a relative binding for the detail page and set the context of the selected row of the master table. This is demonstrated in our Sales Orders sample application. The detail page binding starts in line 199 of Main.view.xml. Setting the binding context is done in line 42 of Main.controller.js. Using this approach you will also get a caching of the detail data per context, i.e. when switching the selected row to a row for which details were already displayed, these detail data do not need to be reloaded. Already reading all items via a For enhancement 2 I will need to talk to some colleagues. Best regards |
Thank you so much for your precise and timely responses! |
Hi Werner, regarding enhancement 2. First of all, let me shortly mention how you could achieve this today with the V4 model. As to when to create the new row: In general, the new row can be created as soon as the list binding is available, i.e. also before data is read. The Now to the requirement part: Our architect asked whether the default row would not fit better in the controls. Could you please provide which controls you plan to use here? I could then get in contact with the respective colleagues. Best regards |
Thanks. Will try the things out but will need time. I am sure your proposal will work. In regards to controls I would see
|
Thank you! Best regards |
I mailed colleagues responsible for controls. Let's see ... |
Hello @wernerdaehn , Thanks for your feedback. Best Regards, |
Hi Werner, has my proposal worked out? Best regards |
Yes, what has been said makes total sense. I still believe the documentation could be a bit more clear and complete, though. For example, at the moment I am stuck here: Goal is to read the odata v4 manually...
Question 1: Question 2: Question 3: But these are really follow up questions. The case as such can be closed - I step back from my request, you convinced me your approach is better. |
@wernerdaehn :
But in essence, the code still needs to handle each context individually. Question 3: When using Best regards |
Could you please outline where you see potential for documentation improvements? Many thanks |
Regarding question 3, how would you use the oDataModel manually, without a control. A model is created with URL etc, now I would like to execute an odata request equivalent to http://..../srv/ENTITY?$select=COL1. Just some arbitrary thoughts regarding docs... Under Essentials:
API Reference: Some more details about the binding per my questions.
Things I struggled with for a long time for whatever reason and don't know where to put it and if I am the only one:
|
Hello @wernerdaehn ! "I would love to see a few lines on how to use the model standalone" Did you spot Accessing Data in Controller Code already? "When does the model query the metadata" When needed. We hope you do not need to know more. It should just work. "how about the skipToken (oData paging), who sets $offset and $top" Normally, a control is using a list binding and then paging happens automatically, via $skip and $top. Server-driven paging is also supported since 1.72. "I did not get the point initially that Model-Control binding and oDataModel-Fieldbinding is something different." I do not get your point here, sorry. A binding context is used on a control level to provide a reference point for relative bindings, for example, the entity instance that "{FirstName}" would refer to. For a (property) binding, this is what you define via Binding#setContext. I agree that there are some confusing terms. Best regards, |
ad 1) "Accessing Data in the Controller Code"? Initially no, but it was the first response and very helpful. But it answers only questions once the data request was defined, how to read the data. ad 2) As said, with controls all works perfectly. All questions are about cases where the model is used manually. For the JSONModel this is described very well but also simple. ad 3) Should be mentioned somewhere, in my opinion. ad 4) Control vs Model binding: When I hear the term Binding, it is about XMLView and mappings like items={/data}. Hence the text about odata binding a model etc I did not get initially at all, as I did not see any relationship to controls. Only later in this thread it was pointed out that you use the term binding to bind fields to the model also, not only controls. That cleared up a lot and I am not sure if I am the only one. |
Hi @wernerdaehn , I think Thomas and I are struggling a bit to understand what could be improved.
I do not get what you mean by "once the data request was defined"? You create a context or list binding with a path, parameters, ... This already defines most of the data request. Then you access the data.
With JSONModel or v2.ODataModel data requests may be triggered explicitly using methods like
It seems that we have nothing on Paging in the documentation and hence also nothing on Server-Driven Paging. The What's New of SAPUI5 1.72 contains some information.
In the end, bindings are object instances. These bindings are for providing access to data in the model. There is a set of defined methods by which controls access and modify data through bindings. And the model creates requests for the backend as required for fulfilling the API calls.
So with the V4 model bindings have become more than the glue between model and controls. Is that going in the direction of the missing piece? Best regards |
Thanks Mathias. I have the feeling we should simply close the case. You have helped a lot already, I have learned much and yes, your answers are going into the right direction. I also believe I got an answer to my most important question, the "how to use the v4.oDataModel to retrieve data manually. Per my understanding I need to bind the properties also. Anyway, worst case I will debug a bound sap.m.table in order to get the missing pieces. Deal? Thank you so much Werner |
Hi Werner,
It must not be necessary to bind the properties relative to the list binding with autoExpandSelect when using
Deal.
You are welcome. Best regards |
Regarding the manual binding, I am very close. This code works, except that I request a list of objects, hence bindContext is wrong, should be bindList.
It does everything I want, most important the requested URL contains the bound fields. It throws an error "failed to drill-down" as I request an Object but it actually is an array (list). Fine. What would be the equivalent for a list binding???
Per my understanding the oModel.bindProperty("WEEK_START_DATE", oListContext); needs the list-binding's context at that point in time, to tell that this binding is relative to the list. But its value is undefined at that point in time as oList.getContext() returns undefined and there are no other suitable methods. In the first example the bindContext().getBoundContext() provided that... |
Hi Werner, let me paste my examples using the TripPin service and the change that we are preparing to fix that Context Binding
Resulting request: List Binding
Resulting request: The creation of the property bindings as in your example is possible and will also work. But it adds a lot of complication and hence must not be necessary when using As written above, we are preparing a change by which the provided Best regards |
Absolutely, Mathias. |
…, $select and no children PS1: integration test & POC PS2: improved POC PS3: TDD PS4: Github reference PS5-6: review comments Change-Id: I2532f45a3878fc0ec1b2f9261101e37716898e7c BCP: 2070245603 Fixes: #2766
And here an example I used. Super simple to use, this oData V4! This is the desired oData query:
|
OpenUI5 version: 1.73.2
In a JsonModel and using the Controller to create the models, things are easy. You define the model and assign it to the view. In case you need to load the model because the value is needed for another control (master-detail), the loaddata method has a parameter for synchronous loading. You can access the jsonmodel after it had been read and manipulate the data, e.g. add a default row, set the selected value to the first entry and the such.
I have to admit, I fail doing that in the v4 odatamodel and with manifests.
Need to look into the details more but found a preload=true property at the model declaration. So that's good.
Now I want to add an event listener to modify the data after it had been loaded (list of all users plus a row with the value "*" to search in all users).
The detail control should not load the data until the filter has been set.
This is a simple master-detail case with both using odata v4.
I believe some more documentation would be needed for that and maybe a feature request or two.
Enhancement 1: support model references in the odata filter
My example of a list referencing a filter from another model, thus the system knows the order of the models to load and what to wait for.
Enhancement 2: Some sort of "default row" property to be included in the data.
Thanks!
The text was updated successfully, but these errors were encountered: