Wicket checkbox example

Wicket example to create a checkbox, and checked the checkbox automatically.

import org.apache.wicket.markup.html.form.CheckBox;
final CheckBox chk0 = new CheckBox("checkbox0", Model.of(Boolean.TRUE));	
final CheckBox chk1 = new CheckBox("checkbox1", new PropertyModel<Boolean>(this, "checkbox1"));

<input type="checkbox" wicket:id="checkbox0" />
<input type="checkbox" wicket:id="checkbox1" />

1. Wicket checkbox example

Different ways to render checkboxes, checked the “chk0” and “chk2” by default.

Checked by default ?
To checked a checkbox, you just need to assign a “true” to the component. This concept applied to other web application frameworks as well.

File : CheckBoxPage.java

package com.mkyong.user;

import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.form.CheckBox;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;

public class CheckBoxPage extends WebPage {

	private boolean checkbox1 = false; // uncheck
	private boolean checkbox2 = true; // checked by default

	public CheckBoxPage(final PageParameters parameters) {

		add(new FeedbackPanel("feedback"));

		final CheckBox chk0 = new CheckBox("checkbox0", Model.of(Boolean.TRUE));

		final CheckBox chk1 = new CheckBox("checkbox1",
				new PropertyModel<Boolean>(this, "checkbox1"));

		final CheckBox chk2 = new CheckBox("checkbox2",
				new PropertyModel<Boolean>(this, "checkbox2"));

		Form<?> form = new Form<Void>("userForm") {
			protected void onSubmit() {

				info("checkbox0 : " + chk0.getModelObject().toString());
				info("checkbox1 : " + Boolean.toString(checkbox1));
				info("checkbox2 : " + Boolean.toString(checkbox2));



2. Wicket HTML page

Page to render 3 checkboxes.

File : CheckBoxPage.html

label {
	background-color: #eee;
	padding: 4px;

.feedbackPanelINFO {
	color: green;
	<h1>Wicket Checkbox Example</h1>

	<div wicket:id="feedback"></div>
	<form wicket:id="userForm">
			<label>CheckBox 0 :</label> 
			<input type="checkbox" wicket:id="checkbox0" />
			<label>CheckBox 1 :</label> 
			<input type="checkbox" wicket:id="checkbox1" />
			<label>CheckBox 2 :</label> 
			<input type="checkbox" wicket:id="checkbox2" />
		<input type="submit" value="Register" />


3. Demo

Start and visit – http://localhost:8080/WicketExamples/

The “chk0” and “chk2” are checked by default.

wicket checkbox
wicket checkbox example
Download it – Wicket-Checkbox-Example.zip (7KB)


  1. Wicket Checkbox Javadoc
author image


Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities. Read all published posts by


newest oldest most voted
Remonty Kraków
Remonty Kraków

Hi I love your work it’s always very helpful but this one can get little confisung when you take a first look. The first code box isint costistend with second one and there is this weird form.add(address); Maybe im just overreactiong but maybe you should take a look.

Marc Schneider
Marc Schneider

Your Blog is great! Good work 🙂

Alan Christian
Alan Christian

I really like this blog, is very useful and straightforward when doubts.

Wicket Tutorials

[…] Checkbox example Uses Checkbox to render checkbox, and checked it by default. […]