Buy me a coffee :)

Wicket - jQuery UI

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

Sliders, with options

16
Model object is: 16
4
Model object is: 4



Components / Samples

Description

The Slider is a form component, having a IModel. Additionally a Label could be used to dynamically display the value as it's changing

Sources

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

import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.model.Model;

import com.googlecode.wicket.jquery.core.resource.StyleSheetPackageHeaderItem;
import com.googlecode.wicket.jquery.ui.form.button.AjaxButton;
import com.googlecode.wicket.jquery.ui.form.button.Button;
import com.googlecode.wicket.jquery.ui.form.slider.Orientation;
import com.googlecode.wicket.jquery.ui.form.slider.Slider;
import com.googlecode.wicket.jquery.ui.form.slider.Slider.Range;
import com.googlecode.wicket.jquery.ui.panel.JQueryFeedbackPanel;

public class OptionSliderPage extends AbstractSliderPage
{
	private static final long serialVersionUID = 1L;

	// Models //
	private final Model<Integer> model1 = Model.of(16);
	private final Model<Integer> model2 = Model.of(4);

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

		// FeedbackPanel //
		form.add(new JQueryFeedbackPanel("feedback"));

		// Sliders //
		final Label label1 = new Label("label1", this.model1); // the supplied model allows the initial display
		form.add(label1.setOutputMarkupId(true));

		form.add(new Label("model1", this.model1));
		form.add(new Slider("slider1", this.model1, label1).setRange(Range.MIN).setMax(120).setStep(16));

		final Label label2 = new Label("label2", this.model2); // the supplied model allows the initial display
		form.add(label2.setOutputMarkupId(true));

		form.add(new Label("model2", this.model2));
		form.add(new Slider("slider2", this.model2, label2).setOrientation(Orientation.VERTICAL).setMin(1).setMax(10).setStep(3));

		// Buttons //
		form.add(new Button("submit") {

			private static final long serialVersionUID = 1L;

			@Override
			public void onSubmit()
			{
				OptionSliderPage.this.info(this);
			}
		});

		form.add(new AjaxButton("button") {

			private static final long serialVersionUID = 1L;

			@Override
			protected void onSubmit(AjaxRequestTarget target)
			{
				OptionSliderPage.this.info(this);
				target.add(form);
			}
		});
	}

	// Methods //

	@Override
	public void renderHead(IHeaderResponse response)
	{
		super.renderHead(response);

		response.render(new StyleSheetPackageHeaderItem(OptionSliderPage.class));
	}

	private void info(Component component)
	{
		this.info(component.getMarkupId() + " has been clicked");
	}
}
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<head>
<wicket:head>
	<title>Wicket jQuery UI: slider, with options</title>
</wicket:head>
</head>
<body>
<wicket:extend>
	<div id="demo-panel">
		<form wicket:id="form">
			<table>
			
				<!-- horizontal slider -->
				<tr>
					<td width="25">
						<span wicket:id="label1"></span>
					</td>
					<td width="240">
						<div wicket:id="slider1"></div>
					</td>
					<td width="240">
						Model object is: <span wicket:id="model1"></span>
					</td>
				</tr>
				
				<!-- vertical slider -->
				<tr>
					<td>
						<span wicket:id="label2"></span>
					</td>
					<td>
						<div wicket:id="slider2"></div>
					</td>
					<td>
						Model object is: <span wicket:id="model2"></span>
					</td>
				</tr>
			</table>
			<br/>
			<input wicket:id="submit" type="submit" value="Submit" />
			<button wicket:id="button">Ajax Button</button>
			<br/><br/>
			<div wicket:id="feedback" style="width: 360px;"></div>
		</form>
	</div>
</wicket:extend>
</body>
</html>
th, td {
	padding: 5px;
}