Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Spring Spring3.2 The checkbox tag

Related Tutorials


 
 

Share on Google+Share on Google+

The checkbox tag

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

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

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: January 30, 2013

Related Tutorials

Discuss: The checkbox tag  

Post your Comment


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