Buy me a coffee :)

Wicket - jQuery UI

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

Spinner





Components / Samples

Description

Spinner is a form component, its value can be validated and submitted through a form.

Since

wicket-jquery-ui-core-1.4.0
wicket-jquery-ui-core-6.2.0

Sources

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

import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.Model;

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

public class DefaultSpinnerPage extends AbstractSpinnerPage // NOSONAR
{
	private static final long serialVersionUID = 1L;
	private FeedbackPanel feedback;

	public DefaultSpinnerPage()
	{
		final Form<Integer> form = new Form<Integer>("form", Model.of(0));
		this.add(form);

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

		// Spinner //
		final Spinner<Integer> spinner = new Spinner<Integer>("spinner", form.getModel(), Integer.class);
		form.add(spinner.setRequired(false));

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

			private static final long serialVersionUID = 1L;

			@Override
			public void onSubmit()
			{
				DefaultSpinnerPage.this.info(this, form);
			}
		});

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

			private static final long serialVersionUID = 1L;

			@Override
			protected void onError(AjaxRequestTarget target)
			{
				target.add(DefaultSpinnerPage.this.feedback);
			}

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

		form.add(new AjaxButton("toggle") { // NOSONAR
			private static final long serialVersionUID = 1L;

			@Override
			protected void onError(AjaxRequestTarget target)
			{
				target.add(DefaultSpinnerPage.this.feedback);
			}

			@Override
			protected void onSubmit(AjaxRequestTarget target)
			{
				spinner.setEnabled(!spinner.isEnabled());
				target.add(form);
			}
		});
	}

	private void info(Component component, Form<Integer> form)
	{
		this.info(component.getMarkupId() + " has been clicked");
		this.info("The model object is: " + form.getModelObject());
	}
}
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<head>
<wicket:head>
	<title>Wicket jQuery UI: spinner</title>
</wicket:head>
</head>
<body>
<wicket:extend>
	<div id="demo-panel">
		<form wicket:id="form">
			<input wicket:id="spinner" type="text" style="width: 35px;" /><br/>
			<br/>
			<input wicket:id="submit" type="submit" value="Submit" />
			<button wicket:id="button">Ajax Button</button>
			<button wicket:id="toggle">enable / disable</button>
			<br/><br/>
			<div wicket:id="feedback" style="width: 360px;"></div>
		</form>
	</div>
</wicket:extend>
</body>
</html>