public abstract class ProgressiveRendering extends Object
<script>
section defining function display(data)
.
(Call ts_refresh($('someid'))
if using a sortable
table.)
<l:progressiveRendering handler="${it.something()}" callback="display"/>
from your
Jelly page to display a progress bar and initialize JavaScript infrastructure.
(The callback attribute can take arbitrary JavaScript expression to be evaluated in the browser
so long as it produces a function object.)
something()
to create an instance of your subclass of ProgressiveRendering
.
compute()
.
canceled()
.
progress(double)
.
data()
produce whatever JSON you want to send to the page to be displayed.
ui-samples-plugin
demonstrates all this.Modifier | Constructor and Description |
---|---|
protected |
ProgressiveRendering()
Constructor for subclasses.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
canceled()
Checks whether the task has been canceled.
|
protected abstract void |
compute()
Actually do the work.
|
protected abstract net.sf.json.JSON |
data()
Provide current data to the web page for display.
|
protected ExecutorService |
executorService()
May be overridden to provide an alternate executor service.
|
net.sf.json.JSONObject |
news()
For internal use.
|
protected void |
progress(double completedFraction)
Indicate what portion of the work has been done.
|
void |
start()
For internal use.
|
protected long |
timeout()
May be overridden to control the inactivity timeout.
|
protected ProgressiveRendering()
@JavaScriptMethod public final void start()
protected abstract void compute() throws Exception
The security context will be that in effect when the web request was made.
Stapler.getCurrentRequest()
will also be similar to that in effect when the web request was made;
at least, Ancestor
s and basic request properties (URI, locale, and so on) will be available.
Exception
- whenever you like; the progress bar will indicate that an error occurred but details go to the log only@Nonnull protected abstract net.sf.json.JSON data()
While this could be an aggregate of everything that has been computed so far,
more likely you want to supply only that data that is new since the last call
(maybe just {}
or []
),
so that the page can incrementally update bits of HTML rather than refreshing everything.
You may want to make your implementation synchronized
, so that it
can track what was sent on a previous call, in which case any code running in
compute()
which modifies these fields should also temporarily be synchronized
on the same monitor such as this
.
protected final void progress(double completedFraction)
compute()
returns, the work is assumed to be complete regardless of this method.)completedFraction
- estimated portion of work now done, from 0 (~ 0%) to 1 (~ 100%)protected final boolean canceled()
compute()
should periodically say:
if (canceled()) return;
@JavaScriptMethod public final net.sf.json.JSONObject news()
protected ExecutorService executorService()
Timer.get()
protected long timeout()
canceled()
will be true.Copyright © 2019. All rights reserved.