Buy me a coffee :)

Wicket - jQuery UI

jQuery UI integration in Wicket 6.x, Wicket 7.x , Wicket 8.x & Wicket 9.x

Progress-bar


value: 36

Components / Samples

Description

The progress bar in incremented by 8, every second, until it completes.

Sources

package com.googlecode.wicket.jquery.ui.samples.jqueryui.progressbar;

import org.apache.wicket.ajax.AbstractAjaxTimerBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.IAjaxIndicatorAware;
import org.apache.wicket.core.request.handler.IPartialPageRequestHandler;
import org.apache.wicket.extensions.ajax.markup.html.AjaxIndicatorAppender;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.EmptyPanel;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.Model;
import org.apache.wicket.util.time.Duration;

import com.googlecode.wicket.jquery.ui.panel.JQueryFeedbackPanel;
import com.googlecode.wicket.jquery.ui.widget.progressbar.ProgressBar;

public class DefaultProgressBarPage extends AbstractProgressBarPage implements IAjaxIndicatorAware
{
	private static final long serialVersionUID = 1L;

	private final ProgressBar progressBar;
	private final AjaxIndicatorAppender indicator = new AjaxIndicatorAppender();

	public DefaultProgressBarPage()
	{
		final Form<Void> form = new Form<Void>("form");
		this.add(form);

		// FeedbackPanel //
		final FeedbackPanel feedback = new JQueryFeedbackPanel("feedback");
		form.add(feedback.setOutputMarkupId(true));

		// Timer //
		final AbstractAjaxTimerBehavior timer = new AbstractAjaxTimerBehavior(Duration.ONE_SECOND) {

			private static final long serialVersionUID = 1L;

			@Override
			protected void onTimer(AjaxRequestTarget target)
			{
				progressBar.forward(target, 8);
			}
		};

		form.add(timer);

		// ProgressBar //
		this.progressBar = new ProgressBar("progress", Model.of(36)) {

			private static final long serialVersionUID = 1L;

			@Override
			public void onValueChanged(IPartialPageRequestHandler handler)
			{
				info("value: " + this.getDefaultModelObjectAsString());
				handler.add(feedback);
			}

			@Override
			protected void onComplete(AjaxRequestTarget target)
			{
				timer.stop(target); //wicket6

				info("completed!");
				target.add(feedback);
			}
		};

		form.add(this.progressBar);

		// Indicator //
		form.add(new EmptyPanel("indicator").add(this.indicator));

		// Initialize FeedbackPanel //
		this.info("value: " + this.progressBar.getDefaultModelObjectAsString());
	}

	@Override
	public String getAjaxIndicatorMarkupId()
	{
		return this.indicator.getMarkupId();
	}
}
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<head>
<wicket:head>
	<title>Wicket jQuery UI: progress-bar</title>
</wicket:head>
</head>
<body>
<wicket:extend>
	<div id="demo-panel">
		<form wicket:id="form">
			<table>
				<tr>
					<td width="240" colspan="2">
						<div wicket:id="progress"></div>
					</td>
					<td>
						<div wicket:id="indicator"></div>
					</td>
				</tr>
			</table>
			<br/>
			<div wicket:id="feedback" style="width: 360px;"></div>
		</form>
	</div>
</wicket:extend>
</body>
</html>