tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hunter Hillegas <li...@lastonepicked.com>
Subject Re: foreach Problem - Not iterating like expected...
Date Tue, 11 Feb 2003 07:02:26 GMT
Yeah, I figured it out. Thanks a lot for the response.

Hunter

> From: Martin Cooper <martinc@apache.org>
> Reply-To: "Tag Libraries Users List" <taglibs-user@jakarta.apache.org>
> Date: Mon, 10 Feb 2003 23:00:19 -0800 (PST)
> To: Tag Libraries Users List <taglibs-user@jakarta.apache.org>
> Subject: Re: foreach Problem - Not iterating like expected...
> 
> 
> 
> On Mon, 10 Feb 2003, Hunter Hillegas wrote:
> 
>> I have the following code:
>> 
>> <%
>>     System.out.println("Start Page: " + startPage); //DEBUG
>>     System.out.println("End Page: " + endPage); //DEBUG
>> %>
>> 
>> <c:forEach begin="${startPage}" end="${endPage}">
>>     <%
>>         System.out.println("Looping..."); //DEBUG
>>     %>
>> </c:forEach>
>> 
>> When I run this code, I get the following values printed out for start and
>> end:
>> 
>> Start Page: 0
>> End Page: 42
>> 
>> But, the code only loops through one time, instead of looping all the times
>> I would expect... Shouldn't it be counting up through all iterations between
>> 0 and 42?
> 
> Nope. You are making a common mistake - assuming that scripting variables
> and scoped attributes are the same thing.
> 
> The 'startPage' and 'endPage' variables that you are displaying using
> System.out.println() are scripting variables. Scripting variables are not
> visible to the regular JSTL tags - those tags obtain their attribute
> values from scoped attributes (e.g. request or session attributes)
> instead.
> 
> To have your loop behave correctly, you'll need to set startPage and
> endPage as scoped attributes instead of scripting variables.
> 
> --
> Martin Cooper
> 
> 
>> 
>> If I replace the begin and end with 0 and 42 like this:
>> 
>> <c:forEach begin="0" end="42">
>>     <%
>>         System.out.println("Looping..."); //DEBUG
>>     %>
>> </c:forEach>
>> 
>> Then it loops as I would expect.
>> 
>> What am I doing wrong?
>> 
>> Thanks,
>> Hunter
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>> 
>> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


Mime
View raw message