Buy me a coffee :)

Wicket - jQuery UI

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

Time 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 java.util.Calendar;
import java.util.Date;
import java.util.Locale;

import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.head.PriorityHeaderItem;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.Model;
import org.apache.wicket.request.resource.JavaScriptResourceReference;

import com.googlecode.wicket.jquery.core.JQueryBehavior;
import com.googlecode.wicket.jquery.core.resource.JQueryGlobalizeHeaderItem;
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.TimeSpinner;
import com.googlecode.wicket.jquery.ui.panel.JQueryFeedbackPanel;
import com.googlecode.wicket.jquery.ui.samples.SampleApplication;

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

	public TimeSpinnerPage()
	{
		Calendar calendar = Calendar.getInstance();
		calendar.set(0, 0, 0, 14, 30); // 2:30 PM

		final Form<Date> form = new Form<Date>("form", Model.of(calendar.getTime()));
		this.add(form);

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

		// Spinner //
		final TimeSpinner spinner = new TimeSpinner("spinner", form.getModel(), Locale.FRENCH) { // NOSONAR

			private static final long serialVersionUID = 1L;

			@Override
			public void onConfigure(JQueryBehavior behavior)
			{
				super.onConfigure(behavior);

				behavior.add(new JavaScriptResourceReference(SampleApplication.class, "globalize.culture.fr-FR.js"));
			}
		};

		form.add(spinner);

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

			private static final long serialVersionUID = 1L;

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

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

			private static final long serialVersionUID = 1L;

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

			@Override
			protected void onSubmit(AjaxRequestTarget target)
			{
				TimeSpinnerPage.this.info(this, form);
				target.add(form);
			}
		});
	}
	
	@Override
	public void renderHead(IHeaderResponse response)
	{
		super.renderHead(response);

		// important! //
		response.render(new PriorityHeaderItem(new JQueryGlobalizeHeaderItem()));
	}

	private void info(Component component, Form<Date> 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: time spinner</title>
</wicket:head>
</head>
<body>
<wicket:extend>
	<div id="demo-panel">
		<form wicket:id="form">
			<input wicket:id="spinner" type="text" style="width: 100px;" /><br/>
			<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>