Buy me a coffee :)

Wicket - jQuery UI

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

Selectable

  • item #1
  • item #2
  • item #3
  • item #4
  • item #5
  • item #6

Components / Samples

Description

Since

wicket-jquery-ui-core-1.2.1

Sources

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

import java.util.Arrays;
import java.util.List;

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.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.Model;

import com.googlecode.wicket.jquery.core.resource.StyleSheetPackageHeaderItem;
import com.googlecode.wicket.jquery.ui.interaction.selectable.Selectable;
import com.googlecode.wicket.jquery.ui.panel.JQueryFeedbackPanel;

public class DefaultSelectablePage extends AbstractSelectablePage
{
	private static final long serialVersionUID = 1L;

	public DefaultSelectablePage()
	{
		List<String> list = Arrays.asList("item #1", "item #2", "item #3", "item #4", "item #5", "item #6");
		List<String> selected = Arrays.asList("item #2", "item #3");

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

		// Selectable //
		final Selectable<String> selectable = new Selectable<String>("selectable", Model.ofList(selected), list) {

			private static final long serialVersionUID = 1L;

			@Override
			public void onSelect(AjaxRequestTarget target)
			{
				this.info("items: " + this.getDefaultModelObjectAsString());
				target.add(feedback);
			}
		};

		this.add(selectable);

		// ListView //
		selectable.add(new ListView<String>("items", list) {

			private static final long serialVersionUID = 1L;

			@Override
			protected void populateItem(ListItem<String> item)
			{
				item.add(new Label("item", item.getModelObject()));
			}
		});
	}

	// Methods //

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

		response.render(new StyleSheetPackageHeaderItem(DefaultSelectablePage.class));
	}
}
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<head>
<wicket:head>
	<title>Wicket jQuery UI: selectable</title>
</wicket:head>
</head>
<body>
<wicket:extend>
	<div class="ui-widget-content">
		<ul wicket:id="selectable">
			<li wicket:id="items">
				<span wicket:id="item">[label]</span>
			</li>
		</ul>
		<br/>
		<div wicket:id="feedback" style="width: 360px;"></div>
	</div>
</wicket:extend>
</body>
</html>
.ui-selectable .ui-selecting {
	background: #FECA40;
}

.ui-selectable .ui-selected {
	background: #F39814;
	color: white;
}

.ui-selectable {
	list-style-type: none;
	margin: 1em;
	padding: 0;
	width: 30%;
	border: 1px solid #FECA40;
}

.ui-selectable li {
	margin: 2px;
	padding: 3px;
}