10 Commonly Used Spring MVC Form tags

In one of the articles we saw the form handling example for spring mvc. Now we will discuss the 10 Commonly Used Spring MVC Form tags.

To use the tags from this library, add the following directive to the top of your JSP page:
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

Using various Spring MVC Form tags

1. form Tag

This tag renders an HTML ‘form’ tag and exposes a binding path to inner tags for binding. It puts the command object in the PageContext so that the command object can be accessed by inner tags. All the other tags in this library are nested tags of the form tag.

You can bind the form with a named variable as shown below. this is optional.
<form:form commandName=”employee”>

Also check – Spring MVC Form handling Example


2. input Tag

Input tag is used to create a text box in the Form and get data from user.
<form:input path="firstName" />

For a detailed example check – Spring MVC Input tag Example


3. label Tag

Spring MVC label tag is used to display labels on form.
<form:label path="firstName">First Name</form:label>
For a detailed example check – Spring MVC Label Tag Example


4. checkbox / checkboxes Tag

This tag can be used by mapping the checbox to a boolean or a list/map.

Using boolean

Using a List/Map

Also check the link for detailed example on Checkbox Tag -Spring MVC Checbox tag Example


5. radiobutton / radiobuttons Tag

Similar to checkbox, radiobutton can also be mapped using multiple syntax

Or

Also check the link for detailed example on RadioButton Tag Spring MVC RadioButton tag Example


6. password Tag

The HTML code that gets generated is

For a detailed example on password tag check the link – Spring MVC Password Tag Example


7. select Tag

Select Tag is used in rendering the dropdown box.

For a detailed example on select tag check the link – Spring MVC Select Tag Example


8. textarea Tag

textarea tag is mainly used when we need the user to fill in a data that’s multiline. e.g a description of a item OR a email message on a form.

For a detailed example on TextArea tag check the link – Spring MVC textarea tag example


9. hidden Tag

In some cases we need data that needs to be send to the server but is not displayed to the user.

In that situation we can use the hidden tag.

For a detailed example on Hidden tag check the link – Spring MVC Hidden tag Examples


10. errors Tag

When a form is submitted the server, we generally validate the form for the correct input values.

Error tags are very useful to show the exact validation error on a specific input field.

Also check the link for detailed example on Error Tag -Spring MVC Error Tag Example


Please do let me know if you need information on any other tags that are not mentioned here.

 

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn