Buy me a coffee :)

Wicket - jQuery UI

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

Auto-complete: custom beans

Select a metal genre: (containing any char)

Components / Samples


The AutoCompleteTextField component allows you to search against a bean list.


As the suggestion list is displayed as text, the bean should either override #toString() or use a ITextRenderer (like TextRenderer). If you plan to use AutoCompleteUtils helper class, the override of #toString() is mandatory.


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

import java.util.List;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.image.ContextImage;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;

import com.googlecode.wicket.jquery.core.resource.StyleSheetPackageHeaderItem;
import com.googlecode.wicket.jquery.core.utils.ListUtils;
import com.googlecode.wicket.jquery.ui.form.autocomplete.AutoCompleteTextField;

public class CustomAutoCompletePage extends AbstractAutoCompletePage
	private static final long serialVersionUID = 1L;

	public CustomAutoCompletePage()
		// Model //
		final IModel<Genre> model = Model.of(GenresDAO.newGenre());

		// Form //
		final Form<Void> form = new Form<Void>("form");

		// Container for selected genre (name & cover) //
		final WebMarkupContainer container = new WebMarkupContainer("container");

		container.add(new ContextImage("cover", new PropertyModel<String>(model, "cover")));
		container.add(new Label("name", new PropertyModel<String>(model, "name")));

		// Auto-complete //
		form.add(new AutoCompleteTextField<Genre>("autocomplete", model) {

			private static final long serialVersionUID = 1L;

			protected List<Genre> getChoices(String input)
				return ListUtils.contains(input, GenresDAO.all());

			protected void onSelected(AjaxRequestTarget target)
				target.add(container); // the model has already been updated

	// Methods //

	public void renderHead(IHeaderResponse response)

		response.render(new StyleSheetPackageHeaderItem(CustomAutoCompletePage.class));
<!DOCTYPE html>
<html xmlns:wicket="">
	<title>Wicket jQuery UI: auto-complete (custom bean)</title>
	<div id="demo-panel">
		<form wicket:id="form">
					<td style="width: 300px; vertical-align: top;">
						<div>Select a metal genre: (containing any char)</div>
						<input wicket:id="autocomplete" type="text" size="30" />
					<td wicket:id="container" style="width: 100px;">
						<img wicket:id="cover" class="ui-corner-all" />
						<div wicket:id="name" style="text-align: center;"></div>
table {
	width: 400px;
	border-spacing: 0;
	border-collapse: collapse;

th, td {
	padding: 5px;

.ui-autocomplete {
	max-height: 200px;
	overflow-y: auto;
	overflow-x: hidden;
	padding-right: 20px;