Skip to content

Progressbar

mocleiri edited this page Jan 22, 2011 · 3 revisions

Progress Bar Project

Wicketstuff progressbar provides a progress bar component for wicket.

The component can be used both for displaying just a progress bar or for showing progress of a background task. The progress of a background task is updated via AJAX.

The wicketstuff-progressbar-spring subproject is a task service implementation for the integration of user submitted background tasks in the service layer with the progress bar.

Maven Artifacts

  • progressbar
  • progressbar-spring
  • progressbar-example

Documentation

The ProgressBar component uses a special model of type ProgressionModel. The current progress is encapsulated in a Progression value-object as the percentage of completion.

The onFinished method is executed when the progress reaches 100 or more generally if the Progression object returns true for isDone.

The progress bar is started to update itself with the start method and stops if the progress is done.

SimpleProgressExamplePage.java:

private int progress = 0;

public SimpleProgressExamplePage() {
    final ProgressBar bar;
    add(bar = new ProgressBar("bar", new ProgressionModel() {
        protected Progression getProgression() {
            return new Progression(progress);
        }
    }) {
        protected void onFinished(AjaxRequestTarget target) {
            setVisible(false);
            target.appendJavascript("alert('Task done!')");
        }
    });
    ...
    form.add(new IndicatingAjaxButton("submit", form) {
        protected void onSubmit(AjaxRequestTarget target, Form form) {
            bar.start(target);
            new Thread() {
                public void run() {
                    for(int i = 0; i <= 100; i++) {
                        try {
                            Thread.sleep(200);
                        } catch (InterruptedException e) { }
                            progress = i;
                        }
                }
            }.start();
        }
    });
    ...
}

Note: The background process shouldn't be started as a new thread from within the page but rather in a seperate service (see wicketstuff-progress-spring).

On the markup side, just use a div element for the progress bar:

SimpleProgressExamplePage.html

...
<div wicket:id="bar">[Progress]</div>
...
Clone this wiki locally