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!


9 responses to “Prevent a Lag when Refreshing an Embedded View in XPages”

  1. Brian Moore says :

    Great post – I hereby name you “ViewMan”. You can pick up you cape anytime.


  2. Paul Withers (@PaulSWithers) says :

    I’m glad I was able to help, and even more glad you were able to take my “this might work” suggestion, prove it and blog about it. Good luck at trying to lose the tag of a view expert 😉

  3. davidleedyDavid Leedy says :

    Guys … I’m worried about performance here… doesn’t that refresh the backend view at a pretty high cost potentially? Or am I missing something?
    I had something similar happen and ended up needed to do a second partial refresh via a CSJS onComplete. So that might be an option for you as well.

    • Brad Balassaitis says :

      Performance is a valid concern when using a technique like this. If it’s a huge application that’s already unwieldy, then it’s probably not a good idea. But in an application where the timeliness of the refresh is important and the extra cost is manageable by the server, then this should be fine.

  4. ddos vps says :

    It is not my first time to visit this web page, i am visiting this website dailly and obtain nice data from here every day.|

  5. dregos says :

    Hi.. is it possible to grab a repeatcontrol like that and refresh it’s datasource?

  6. myunus says :

    saved may day, thank you.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: