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:
- 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)
- If the value was present in the cache, render it
- 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.