You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Nic Werner <ni...@link11.net> on 2003/10/12 23:33:48 UTC
Simple iteration
This is a simple question, but is there any way to count *backwards* in JSTL?
Using the forEach tag, if begin=10 and end=0, I get an: 'end' < 0 error
I've also tried using step="-1" to no avail.
Basically, I want to create a year pulldown box which starts at the
currentyear and then displays the previous twenty years.
<c:forEach begin="${currentYear}" end="${currentYear-20}" step="-1"
var="year"> <option> <c:out value="${year}"/></option> </c:forEach>
- Nic
---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
RE: Simple iteration
Posted by Carlos Sanchez <ap...@cousas.net>.
The JSTL specification is clear:
Constraints
If specified, begin must be >= 0.
If end is specified and it is less than begin, the loop is simply not
executed.
If specified, step must be >= 1
> -----Mensaje original-----
> De: Nic Werner [mailto:nic@link11.net]
> Enviado el: lunes, 13 de octubre de 2003 0:14
> Para: apache@cousas.net
> CC: taglibs-user@jakarta.apache.org; nic@link11.net
> Asunto: RE: Simple iteration
>
>
> Heh, yeah that was my workaround eventually, but I just felt
> that there has to be a better way. It surprises me the tag
> only supports one direction.
>
> Not being to start from a negative number while simply
> 'counting' is odd also. Of course, iterating through a
> collection wouldn't work, but just counting.
>
> So I guess if you had a collection of items and you wanted to
> iterate backwards you would just use the same principle as
> below but use the index instead.
>
> > Why not
> >
> > <c:forEach begin="0" end="20" var="i">
> > <option>
> > <c:out value="${currentYear-i}"/>
> > </option>
> > </c:forEach>
> >
> >
> >> -----Mensaje original-----
> >> De: Nic Werner [mailto:nic@link11.net]
> >> Enviado el: domingo, 12 de octubre de 2003 23:34
> >> Para: taglibs-user@jakarta.apache.org
> >> Asunto: Simple iteration
> >>
> >>
> >> This is a simple question, but is there any way to count
> >> *backwards* in JSTL?
> >>
> >> Using the forEach tag, if begin=10 and end=0, I get an: 'end' < 0
> >> error
> >>
> >> I've also tried using step="-1" to no avail.
> >>
> >> Basically, I want to create a year pulldown box which
> starts at the
> >> currentyear and then displays the previous twenty years.
> >>
> >> <c:forEach begin="${currentYear}" end="${currentYear-20}"
> step="-1"
> >> var="year"> <option> <c:out value="${year}"/></option> </c:forEach>
> >>
> >> - Nic
> >>
> >>
> >>
> >>
> ---------------------------------------------------------------------
> >> 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
RE: Simple iteration
Posted by Nic Werner <ni...@link11.net>.
Heh, yeah that was my workaround eventually, but I just felt that there
has to be a better way. It surprises me the tag only supports one
direction.
Not being to start from a negative number while simply 'counting' is odd
also. Of course, iterating through a collection wouldn't work, but just
counting.
So I guess if you had a collection of items and you wanted to iterate
backwards you would just use the same principle as below but use the index
instead.
> Why not
>
> <c:forEach begin="0" end="20" var="i">
> <option>
> <c:out value="${currentYear-i}"/>
> </option>
> </c:forEach>
>
>
>> -----Mensaje original-----
>> De: Nic Werner [mailto:nic@link11.net]
>> Enviado el: domingo, 12 de octubre de 2003 23:34
>> Para: taglibs-user@jakarta.apache.org
>> Asunto: Simple iteration
>>
>>
>> This is a simple question, but is there any way to count
>> *backwards* in JSTL?
>>
>> Using the forEach tag, if begin=10 and end=0, I get an: 'end'
>> < 0 error
>>
>> I've also tried using step="-1" to no avail.
>>
>> Basically, I want to create a year pulldown box which starts
>> at the currentyear and then displays the previous twenty years.
>>
>> <c:forEach begin="${currentYear}" end="${currentYear-20}"
>> step="-1" var="year"> <option> <c:out
>> value="${year}"/></option> </c:forEach>
>>
>> - Nic
>>
>>
>>
>> ---------------------------------------------------------------------
>> 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
RE: Simple iteration
Posted by Carlos Sanchez <ap...@cousas.net>.
Why not
<c:forEach begin="0" end="20" var="i">
<option>
<c:out value="${currentYear-i}"/>
</option>
</c:forEach>
> -----Mensaje original-----
> De: Nic Werner [mailto:nic@link11.net]
> Enviado el: domingo, 12 de octubre de 2003 23:34
> Para: taglibs-user@jakarta.apache.org
> Asunto: Simple iteration
>
>
> This is a simple question, but is there any way to count
> *backwards* in JSTL?
>
> Using the forEach tag, if begin=10 and end=0, I get an: 'end'
> < 0 error
>
> I've also tried using step="-1" to no avail.
>
> Basically, I want to create a year pulldown box which starts
> at the currentyear and then displays the previous twenty years.
>
> <c:forEach begin="${currentYear}" end="${currentYear-20}"
> step="-1" var="year"> <option> <c:out
> value="${year}"/></option> </c:forEach>
>
> - Nic
>
>
>
> ---------------------------------------------------------------------
> 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