Prevent a Lag when Refreshing an Embedded View in XPages
Have you gotten frustrated with delays in refreshing a view embedded on an XPage? Fortunately, there’s an easy fix.
I recently worked on an application that had an embedded form and view for related documents displayed within a main form. The embedded view used a category filter to only display documents related to the main form, based on a shared ID.
The save button on the embedded form was set to partially refresh the embedded view. However, when a document was created via the embedded form, the view wasn’t immediately updated with that new document.
When I would add or edit another document via the embedded form (thus triggering the refresh on the view again), the view would then show the first document that was added. It was always one refresh behind when adding a new document.
I discussed it with Paul Withers, and we determined that the new documents weren’t showing up when the view was refreshed due to a timing issue. The view index wasn’t being updated fast enough for the new document to appear in the view when refreshed on screen.
Fortunately, there’s a pretty simple solution. It uses a method similar to technique I described in a recent post — getting a handle to the underlying view and acting upon it.
Once we have that handle, we can force it to refresh, so that when the partial refresh is executed, the underlying view’s index is up-to-date and the new document will be included in the updated view on screen.
To put it in practice, just include this line on the ‘Save’ button that saves the new document from the embedded form (and ensure that the button is set to partially refresh the view panel).
That’s all there is to it!