The checkbox tag

In this section, you will learn about Spring form tag library.

Ads

Tutorials   
Spring 3.2 MVC insert and retrieve blob from the database The hidden tag The errors tag net.roseindia.dao net.roseindia.service net.roseindia.model net.roseindia.controller Spring 3.2 MVC Hibernate Example Spring 3.2 MVC, Upload File in a specific folder Spring 3.2 MVC Form Handling The textarea tag The options tag The option tag The select tag The radiobuttons tag The radiobutton tag The checkboxes tag mvc:default-servlet-handler Static Resources Configuration View Controllers Configuration View resolvers Spring 3.2 MVC Hello World Example Content Negotiation Configuration Interceptors Configuration using Java or XML Customizing the MVC Java config or XML Namespace MVC Java Config or the MVC XML Namespace Servlet container initialization through code Support for ETag The checkbox tag Autogenerated logical view name through RequestToViewNameTranslator Modification in conventional ModelAndView ControllerClassNameHandlerMapping class for handling convention mapping The password tag The input tag The form tag Form Tag library configuration Customizing the Default Error Page @ExceptionHandler & @ResponseStatus annotation Multipart support for file upload in Spring MVC Themes and Theme resolvers in Spring MVC Locales in Spring MVC ContentNegotiatingViewResolver Redirecting and forwarding to views Chaining of Multiple view resolvers View Resolving through ViewResolver interface Requests Intercepting through a HandlerInterceptor Defining handler methods using @RequestMapping annotation Spring 3.2 Asynchronous Request Processing @RequestMapping annotation for mapping requests @Controller annotation for defining new controller
Ads

The checkbox tag

In this section, you will learn about Spring form tag library.

The checkbox tag of Spring form tag library provides HTML 'input' tag of 'checkbox' type.

To understand it completely, let us take an example :

A user need to fill their details in a registration form. The detail can be fill in the form using input field, checkbox etc.

Given below class Registration :

public class Registration
{
	private String firstName;
	
	private String lastName;
	
	private String category[];
	
	public String getFirstName() {
	return firstName;
	}
	
	public void setFirstName(String firstName) {
	this.firstName = firstName;
	}
	
	public String getLastName() {
	return lastName;
	}
	
	public void setLastName(String lastName) {
	this.lastName = lastName;
	}
	
	public String[] getCategory() {
	return category;
	}
	public void setCategory(String[] category) {
	this.category = category;
	}
}

The form.jsp using above Registration class should be like :

<form:form>
	<table>
		<tr>
			<td>First Name:</td>
			<td><form:input path="registration.firstName" /></td>
			</tr>
		<tr>
			<td>Last Name:</td>
			<td><form:input path="registration.lastName" /></td>
		</tr>
		<tr>
			<td>Category:</td>
			<td>
			Sports: <form:checkbox path="registration.category" value="Sports"/>
			Science: <form:checkbox path="registration.category" value="Science"/>
			Current Affairs: <form:checkbox path="registration.category"
			value="Current Affairs"/>
			</td>
		</tr>
	</table>
</form:form>

The above file will be rendered like this :

<form method="POST">
	<table>
	<tr>
		<td>First Name:</td>
		<td><input name="firstName" type="text" value="Harry"/></td>
	</tr>
	<tr>
		<td>Last Name:</td>
		<td><input name="lastName" type="text" value="Potter"/></td>
	</tr>
	<tr>
		<td>Category:</td>
	<td>
	Sports:<input name="registration.category" type="checkbox" value="Sports"/>
	<input type="hidden" value="1" name="_registration.category"/>
	Science:<input name="preferences.interests" type="checkbox" value="Science"/>
	<input type="hidden" value="1" name="_preferences.interests"/>
	Current Affairs: <input name="registration.category" type="checkbox" value="Current Affairs"/>
	<input type="hidden" value="1" name="_registration.category"/>
	</td>
	</tr>
	</table>
</form>


Advertisements

Ads
Share on Google+Share on Google+

The checkbox tag

Posted on: January 30, 2013 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: The checkbox tag  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0

Ads

 

Ads