How to refresh all (OData) bindings of a given SAPUI5 page? - odata

I have a bigger SAPUI5 application with multiple pages.
If user navigates through all these pages, they will reside in memory of course.
Now I have the problem that some of these pages have a complex context with several bindings to an ODataModel. That leads to the problem that a .refresh() call on the underlying ODataModel take some time.
Because: all known bindings will be reloaded (also from pages not currently shown)
Now I am searching for a better solution to refresh the ODataModel.
The refresh must be done because sometimes a client action triggers the server to updates multiple data (in different models!).
Further information (Edit)
I am using multiple ODataModels in my application and they are created in the Component.js (as suggested in the Best practice chapter of the SDK documentation).
Navigating through the pages will increase the cached data in the ODataModel.
Calling a .refresh() seems to reload all cached data (still used or not).
According to the first reply it is possible to refresh one binding but how to refresh all bindings of a given view/page with multiple models?
Would it be the right way to set multiple instances of the ODataModel for each view? And just call the .refresh() method there? But also on this scenario the locally cached data will increase over time?
Any ideas welcome :)

You can access the binding of a specific UI control and call refresh there. This should just process this specific binding.

My first hint would be to use the v2 OData Model (sap.ui.model.odata.v2.ODataModel), as it uses the Batch Mode by default.
Moreover, when it performs updates, it refreshes all bindings of entities that have been updated automatically so you should not need to refresh the whole model at all.

For me it worked to just re-bind that binding on a specific element in the view as I did earlier to create it at all.
We had an update-problem after another update call had side effects on the information in question, but a refresh on the binding of the elemnt itself did not solve that. I guess there were no local changes to that path in the model, so there was nothing to refresh. But on server-side there where updates the model/Cache didn't know about. Rebinding made my day, and also only the one necessary call to the servcie was made.

Related

Umbraco automatic update

I need some help with umbraco.
Let's say that I have an umbraco grid with a custom editor, just like the one in this tutorial: https://our.umbraco.com/documentation/Getting-Started/Backoffice/Property-Editors/Built-in-Property-Editors/Grid-Layout/build-your-own-editor
Ok, so I wrote this editor to build a gallery of items with image/title, I get the item list from an api call made by an angular service and this works fine when I publish the page by hand. What I want is to automatically update this gallery with new items where available, so my idea was to make a timed ajax call, let's say every hour, to update the items. But sadly this doesn't work, I suppose that the call is made but the list isn't updated.
Any suggestion? Thanks
You need to handle this differently. Right now it sounds like what you have is an implementation that works when you are browsing to this node in the backoffice using your browser and the browser makes the API calls through Angular. This all happens in your UI and when you manually hit save/publish - the data in the UI gets saved. Keep in mind that this is basically your browser doing the "work" - and this (and all other Angular code) will of course only ever run while your browser is open, in the backoffice, viewing this node.
What you want to do is to have this run automatically (and preferably in some sort of background task) to ensure that you do not really have to open up the backoffice for this to actually be automatically updated over time.
You need to create some sort of background job running on the server-side instead. This would have to be done in C# and I would recommend looking into Hangfire or Quartz frameworks to handle all the scheduling/making sure the job runs.
This job/task should do the external API calls in C# and transform the result into the same format as the format you are saving when you save data from the manual update. Then fetch the content nodes you need to update using the ContentService API and update the specific property values on those nodes. When this is done you need to make sure the changes are saved and the node is then republished with its updated data. All of this is done through the ContentService.

Hold a data object temporarily in MVC controller,MVC,MVC Controller temp storage

I have a object that i want to store for a moment. The object is in a controller for now, the controller will generate a view. A AJAX request is made from the view to next controller. For that moment i need the object previously stored. Previously, i used session and it worked well. But not sure it is the right thing to do. Is session the answer for this or is there anything else?
I have used cache also.but as per the cache concept.It will access for all the users.So one user data will be override to another.So the cached object data will be change for the same user.I need to handle the data storage for an particular user(Independent).
How is it possible? anyother approach is there please share me.
In Controller I have used Httpcontext.cache["key"]=dataset;
but some one suggested like this.but its not displaying
Explain:
In Controller: httpcontext.current.cache is not coming.
HttpContext.Currenthandler and HttpContext.Currentnotification properties only coming.So How can we handle the temp data storage in MVC.
Please help me.
You could use TempData if you want to store data for the next request only. If data should be accessible between multiple requests, then use Session. Here is short explanation of each one with examples.
As Alex said you could use TempData but if you want to use the data in multiple request, you could use TempData.Keep("YourKey") after reading the value to retain the data for the next request too. For your Information TempData internally uses Session to store your data (temporarily)
I would recommend URL parameters for a HTTP Get, or hidden form fields for a HTTP Post, if this is short lived. This is highly about avoiding the session.
But if it should really persist, then a database might be a reasonable location. Imagine a shopping cart that you don't want to dump just because a session timed out; because you'd like to remind the user next time about items they still haven't purchased.
Why not use the session? I don't generally recommend using the session, as you could find yourself with a global variable that two different browser windows are manipulating. Imagine a glass. One window is trying to fill it with Ice Tea. Another window is trying to fill it with Lemonade. But what do you have? Is it Lemonade? Is it Ice Tea? Or is it an Arnold-Palmer? If you try to put too much stuff on the session, and overly expect it to just be there, you might create an application that is non-deterministic if heaven forbid a user opens a second window or tab, and switches back and forth between the windows.
I'm more ok with Temp Data, if you truly have no other options. But this is not for persisting data for more than a second. Temp data will disappear after the first request reads it, as in, it's meant for a very temporary usage.
I personally only use TempData if I have to do a redirect where I can't otherwise keep it with me, or if I need to have that data for say generating a PDF or image that is going to be called via a HTTP Get by a viewer on the actual page, and then only if the model data is too large for the GET url ( many browsers only support just over 2000 characters, which long description or many fields could fill up.)
But again, pushing items around in hidden form variables, or in url parameters can be safe, because you have no multiple window use conflicts (each carries around its own data for peace of mind.)

"State" management for asp.net mvc multi partial view + ajax app

I am trying to convert my asp.net mvc4 app, which had fairly heavy use of SessionState, into a stateless app. I understand that I can store this information in the DB, and intend to do so.
My question, though, is about my particular architecture. My app has a main 'page' consisting of a number of partial view panels, which each have actions in them that can affect the other panels. What i've been doing up to now is storing the entire state of the viewModel (lots of inter-related EF list collections and 'record' objects) in the session, and its been working great. Except when the session just randomly dies.
So, I need to get this data out of the session, and into the DB where I can rebuild the thing at need. My concern is that, if I store the info in the database, every single action done on screen might affect 3-5 different panels, each with their own State updates, thats a minimum of 10 round trips to the DB for every interaction!
What are some strategies I can use to make this idea more scalable?
EXTRA INFO
The view in question here is a sort of POS shopping cart system. There are panels for selecting events, selecting/adding items to the cart, editing cart items, selecting contacts, editing contacts, displaying the cart items, displaying the cart 'subtotals', and finally, a panel with a [checkout] button.
Selecting a new event will change the list of available items. Selecting an item to add to the cart will change the cart item list, subtotals, as well as the checkout panel. Same for editing a cart item.
The main concern is how to recover from a lost session, as I've found the built-in asp.net session code too unreliable. My testers have encountered issues with sessions timing out, and then my app not having any kind of recovery process. When its installed on 1500 sites, each with an average of 10 users, its going to be a plague of lost session issues, and I need to combat that before it becomes a real problem.
I agree that I'm not going stateless...wrong choice of words used in a rush. I'm just trying to move that state into a form that I can rely on past the session failure. My main idea presently is to continue using the session as the local cache for the viewModel data, but to have a fallback operation that can rebuild the viewModel from DB if the session one is lost somehow.
You shouldn't necessarily be using a database to store (what sounds like) data that only needs to be persisted in the short term.
If these changes to the other partials are only relevant in the context of the current "master view," then I would suggest using jQuery AJAX to send off the requests, parse the response JSON and update the other views. Tutorials on jQuery AJAX and ASP.NET MVC are easy to find, if you don't already have the knowledge:
http://www.codeproject.com/Articles/41828/JQuery-AJAX-with-ASP-NET-MVC
This way, you don't need to make a bunch of round trips. If the changes need to be persisted beyond the context of the current view, make ONE round trip to the database to perform the update and then simply update all of the other partials from the in-memory response from the AJAX call.
You don't need to read from secondary storage multiple times when you already have all of the information you need in-memory. Just do the reading and writing once.
I decided to go with a hybrid approach. I'm still using session, but I'm building out a DB 'recovery' option, so that if the session portion is lost, the DB will be able to provide the values needed to rebuild the session seamlessly.
Seems to be working well, so far.

How to wipe out all forms/grid data in Silverlight?

I have a Silverlight 3 business app set up with RIA Services. I use a domain datasource to connect to the backend and fetch the data and populate a series of dataforms and grids bound to this datasource.
The issue is that we require tight security and currently when a user logs out and another logs back in on the same machine the forms/grids briefly display information from the last login before the DDS gets the new set.
What's the best approach to wiping out all the data when the user logs out in Silverlight? For legal reasons we can't chance any data hanging around, so is there a way to tell Silverlight to go back to its initial state?
Thanks,
Found my solution: turns out that by simply removing the NavigationCacheMode="Enabled" from each of the pages, logging out now correctly clears out all the form/grid data cleanly and simply.
Before finding this solution though I did run across this method to clear all the form/grid data on a page but for my case, the solution above works much better.

Showing status of current request by AJAX

I'm trying to develop an application which modifies a couple of tasks of the famous Online-TODO List RememberTheMilk (rememberthemilk.com) using the REST API.
Unfortunately the modifying takes a lot of time, so I want to give a feedback to the users.
My idea was just to display a couple of text lines (e.g. modifying task 1 of n...).
Therefore I used the periodically_call_remote on my page and called a which reads a Singleton.
In the request I store the text that should be displayed in the same singleton. But I found out, that once I set up a request, the periodically_call_remote does not update the specified div.
My question to this:
1. is this a good way to implement this behaviour?
2. if it is, how do get the periodically_call_remote to work during a submit?
Using a Singleton is most definitely a bad idea. In an advanced production setup it isn't guaranteed that subsequent requests will go to the same process or to the same machine (and subsequently will have a different Singleton). Plus, if you have many users, I don't even want to think about what'll happen to those poor Singletons.
Does any of this stuff actually need to go through your Rails app? It seems like you can call the RTM API via Javascript from the page the user is on and then update the page when the XHR request is complete.

Resources