public TaskServiceProgressExamplePage()
{
final Form<Void> form = new Form<Void>("form");
final ProgressBar bar;
final TaskProgressionModel progressionModel = new TaskProgressionModel()
{
private static final long serialVersionUID = 1L;
@Override
protected ITaskService getTaskService()
{
return getExampleApplication().getTaskService();
}
};
form.add(bar = new ProgressBar("bar", progressionModel)
{
private static final long serialVersionUID = 1L;
@Override
protected void onFinished(AjaxRequestTarget target)
{
ITaskService taskService = getExampleApplication().getTaskService();
// finish the task!
taskService.finish(progressionModel.getTaskId());
// Hide progress bar after finish
setVisible(false);
// Add some JavaScript after finish
target.appendJavaScript("alert('Task done and finished!')");
// re-enable button
Component button = form.get("submit");
button.setEnabled(true);
target.add(button);
}
});
// Hide progress bar initially
bar.setVisible(false);
form.add(new IndicatingAjaxButton("submit", form)
{
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form)
{
ITaskService taskService = getExampleApplication().getTaskService();
// Schedule and start a new task
Long taskId = taskService.scheduleAndStart(new DummyTask(60));
// Set taskId for model
progressionModel.setTaskId(taskId);
// Start the progress bar, will set visibility to true
bar.start(target);
// disable button
setEnabled(false);