java left logo
java middle logo
java right logo
 

Home arrow Java EE Tips arrow JavaServer Pages arrow JSTL - Handling parameters collection
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 4093
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
JSTL - Handling parameters collection E-mail
User Rating: / 21
PoorBest 

Sometimes there is a need to pass a collection of values from HTML from to server. To achieve that a list of parameters with the same name is used. In our sample form we use a set of checkboxes with the same name.

A collection of parameteres may be accessed through the expression ${paramValues.name}, where name is the name of the parameter you're looking for. The result of such expression contains all these values.

In our tip all the checkbox parameters have the same value for the name attribute: feedback. Users can choose as many check boxes as they feel are appropriate, and the expression ${paramValues.feedback} will contain a collection of all the parameters

A form with checkbox parameters:

...
<form method="post" action="checkbox.jsp">
	<p>
		Please check adjectives you would
		use to describe this web site's
		customer service:
	</p>
	
	<p>Atrocious <input type="checkbox" name="feedback" 
	                value="atrocious"/> </p>
	                
	<p>Loathsome <input type="checkbox" name="feedback" 
	                value="loathsome"/></p>
	                
	<p>Flagitious <input type="checkbox" name="feedback" 
	                value="flagitious"/></p>
	                
	<p>Satisfactory<input type="checkbox" name="feedback" 
	                value="satisfactory"/></p>
	                
	<p><input type="submit" value="Submit" /></p>
</form>
...
////////////// a page to handle checkbox parameters:

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>

<c:choose>

////////////// Decides if there are any feedback params"

	<c:when test="${not empty paramValues.feedback}">
		You described our customer service as
		<ul>
			<c:forEach items="${paramValues.feedback}" var="adj">
				<li><c:out value="${adj}"/></li>
			</c:forEach>
		</ul>
	</c:when>

	<c:otherwise>
		You didn't choose any feedback checkboxes.
	</c:otherwise>
</c:choose>


 Related Tips

 
< Prev   Next >

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.


Name (required)


E-Mail (required)

Your email will not be displayed on the site - only to our administrator
Homepage(optional)



Comment Enable HTML code : Yes No



 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.