Buy me a coffee :)

Wicket - jQuery UI

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

Slider, with input




Components / Samples

Description

Since

wicket-jquery-ui-core-1.1

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.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.Model;
import org.apache.wicket.validation.validator.RangeValidator;

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.Slider;
import com.googlecode.wicket.jquery.ui.panel.JQueryFeedbackPanel;

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

	public InputSliderPage()
	{
		Form<Integer> form = new Form<Integer>("form");
		this.add(form);

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

		// Sliders //
		TextField<Integer> input = new TextField<Integer>("input", Model.of(15), Integer.class);
		form.add(input);

		final Slider slider = new Slider("slider", input.getModel(), input); // input is responsible of the model object
		slider.setRangeValidator(new RangeValidator<Integer>(0, 200));
		form.add(slider.setMin(0).setMax(200));

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

			private static final long serialVersionUID = 1L;

			@Override
			public void onSubmit()
			{
				InputSliderPage.this.info(this, slider);
			}
		});

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

			private static final long serialVersionUID = 1L;

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

			@Override
			protected void onError(AjaxRequestTarget target)
			{
				target.add(form.get("feedback"));
			}
		});
	}

	// Methods //

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

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

	private void info(Component component, Slider slider)
	{
		this.info(component.getMarkupId() + " has been clicked");
		this.info("The model object is: " + slider.getModelObject());
	}
}
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<head>
<wicket:head>
	<title>Wicket jQuery UI: slider, with input</title>
</wicket:head>
</head>
<body>
<wicket:extend>
	<div id="demo-panel">
		<form wicket:id="form">
			<table>
				<tr>
					<td width="240">
						<div wicket:id="slider"></div>
					</td>
					<td width="100">
						<input wicket:id="input" type="text" size="4" />
					</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;
}