• Post Reply Bookmark Topic Watch Topic
  • New Topic

why no while loop tag in JSTL

 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am surprise that there is no direct support for while loop in JSTL. Even though it can be simulated by combination of if and forEach, I feel that JSTL is missing it.
 
Simon Brown
sharp shooter, and author
Ranch Hand
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just out of interest, is there any specific reason that you feel a "while" tag would be a useful addition?
If you take the MVC approach, JSP is used to render the pages of a web application which means that the controller should setup the model appropriately. Using a while loop tends to imply that a certain degree of logic is embedded within the page.
Just my opinion...
Simon
[ October 31, 2002: Message edited by: Simon Brown ]
 
Shawn Bayern
Author
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Simon -- as did the JSTL expert group. We couldn't come up with a compelling reason to introduce a <c:while> tag.
 
Jagadeesh Verri
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In case you don't want to iterate over Collections, you can use <c:forEach> as a conventional loop equivalent by the following approach:

<c:set var="startIndex" scope="page" value="0"/>
<c:set var="endIndex" scope="page" value="12"/>

<select name="milestone_count" id="milestone_count">
     <option value="">-select-</option>
     <c:forEach begin="${startIndex}" end="${endIndex}" step="1" var="index">
         <option value="${index}">${index}</option>
     </c:forEach>
</select>

This will produce a select drop down ranging from 0 to 12
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!