is it possible to have a requestFacotry call in a middle of a render method?

23 views
Skip to first unread message

Elhanan

unread,
Dec 13, 2011, 3:46:42 PM12/13/11
to google-we...@googlegroups.com
hi..

let's say i have a tree which i would like to have for each node along with it's a name a total number of stuff related to that name

is it possible to create SafeHTMLrenderer passed to a custom cell, that in it's render method call a RequestFactory method that will append said number to the label? or do i have to embed allready in the object for the tree? 

Thomas Broyer

unread,
Dec 14, 2011, 5:16:07 AM12/14/11
to google-we...@googlegroups.com
You can do it, but it's a bit tricky, due to the asynchronous nature of the request.

What I did is that I pass a "callback" (I reused the ValueUpdater interface, even though it's not about updating the value, but the method signature was exactly what I needed) to the cell; see below.
You also need a cache for the retrieved data, as the cell can be re-rendered at any time.

The idea is:
  1. ask the cache (you can use the Cell.Context.getKey() as the cache key, or any ProvidesKey for the value being rendered, or the value itself)
  2. If the value was present in the cache, render it
  3. Otherwise, fire the request and render something in the mean time (e.g. "loading…")
    • when the result comes back, put it into the cache and ask to be re-rendered; this is where I use my ValueUpdater: I simply call the updater's update(), and the view that uses the Cell then decides how to do it (in my case, I have a ListDataProvider, so it's as easy as list.set(list.indexOf(value), value); –yes, replacing the value with itself, it's enough to trigger a repaint–)
    • When the Cell will be re-rendered, the value will be in the cache, so the step #2 above will be triggered, instead of step #3, and the retrieved value will be then rendered.
I guess you could also generate a placeholder with a unique ID (using Document.get().createUniqueId()) the first time, and then use Document.get().getElementById() and DOM manipulation (could be as simple as a setInnerHTML) to update the value when the response comes back from the server; instead of triggering a repaint.
Reply all
Reply to author
Forward
0 new messages