Hi, I got a tricky problem, when I convert my JSP for loop into JSTL for loop, I got two String variables in my JSP for-loop, obviously which get iterate every time when my loop get executed and new values are coming.
But when I try to convert it into JSTL for loop( forEach), I am not getting the desired result which I am looking.
I am looking for help, if anyone knows plz help me. Its urgent.
Here is my code:-
JSP for loop
<% try {
for(int i=0; i<alCompanyID.size(); i++)
{
String sCompanyName = (String)alCompanyName.get(i);
String sCompanyID = ((Integer)alCompanyID.get(i)).toString();
%>
<option value="<%= sCompanyID %>"><%= sCompanyName %></option>
<%}}catch(Exception e){}
JSTL forEcah loop
<c:catch var="exception">
<c_rt:forEach begin="0" step="1" end="<%=alCompanyID.size()%>">
<c_rt:set var="CompanyName" scope="page" value="${alCompanyName}" />
<c_rt:set var="CompanyID" scope="page" value="${alCompanyID}" />
<option value="<c_rt:out value="${pageScope.CompanyID}"/>"><c_rt:out value="${pageScope.CompanyName}" /></option>
</c_rt:forEach>
</c:catch>
Thanks
RD
-
Conversion of for loop from JSP to JSTL (2 messages)
- Posted by: Ranendra Das
- Posted on: August 11 2005 09:06 EDT
Threaded Messages (2)
- Conversion of for loop from JSP to JSTL by sven gali on August 25 2005 04:15 EDT
- Looping using JSTL by Bruno Patini Furtado on August 25 2005 12:08 EDT
-
Conversion of for loop from JSP to JSTL[ Go to top ]
- Posted by: sven gali
- Posted on: August 25 2005 04:15 EDT
- in response to Ranendra Das
You're using page scope in the JSTL code. Try using request scope. -
Looping using JSTL[ Go to top ]
- Posted by: Bruno Patini Furtado
- Posted on: August 25 2005 12:08 EDT
- in response to Ranendra Das
The JSP code below might help you.
<%@ page contentType="text/html; charset=ISO-8859-1" language="java"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
java.util.List allCompanyID = new java.util.LinkedList();
allCompanyID.add("Sun");
allCompanyID.add("IBM");
allCompanyID.add("Novel");
request.setAttribute("allCompanyID", allCompanyID);
%>
My Companies
<SELECT NAME="Test">
<c:forEach var="id" items="${allCompanyID}" varStatus="loopStatus">
<option value="${loopStatus.index}">${allCompanyID[loopStatus.index]}</option>
</c:forEach>
</SELECT>