Spring MVC Checkbox Tag Example

In this example we will see different ways of using spring mvc checkbox tag.
You can either use <form:checkbox path="<somevariableName>" /> or
<form:checkboxes path="<somevariableName>" items="<someListName>" /> based on your requirements.

Spring MVC Checkbox Tag can be implemented using 4 different ways

1. Using a boolean variable

2. Using a hard-coded list at Client Side

3. Using a dynamic list from Server Side

4. Using a dynamic Map from Server Side (Defining label and value)

Using a map or a user defined object can be useful when you want to differentiate between the data displayed to the user and data passed back to the server.

Spring MVC Checkbox Tag – Complete Example

We have create a complete example using all the possible ways of implementing the checkbox/checkboxes in spring

1. Create a  Model class


2. Create a Controller Class that will pass data and the model to the view


3. Create View to show the checkboxes to the user.


4. Create a success page to show the data selected by user



Spring MVC Tutorial | Spring MVC Checkbox Tag with Example

After Selecting some values you will see the output

Spring MVC Checkbox Tag with Example | Spring MVC Tutorial


Note that the values selected for the Social Profiles are the Key’s that we had passed in the Map from Server Side.

Download the Source Code : – SpringMVC-CheckBoxTagExample.zip