| Author |
JSTL and c:if problem
|
Miki Italiano
Greenhorn
Joined: Mar 07, 2004
Posts: 7
|
|
I think I might already know what the problem is, but I wanted to share and see if anyone believes the same... Here is a snippet of code in my results jsp page... <td colspan=4> <!-- set the end index of the current page --> <c:set var="endIdx" scope="page"> <c:if test="${(startIndex+size) < total}"> <c ut value="${startIndex+size-1}"/> </c:if> <c:if test="${(startIndex+size) >= total}"> <c ut value="${total}"/> </c:if> </c:set> <!-- display buttons when appropriate --> <c:if test="${startIndex} > 1"> <html:submit property="submit">Prev</html:submit> </c:if> <c ut value="${startIndex}"/> to <c ut value="${endIdx}"/> of <c ut value="${total}"/> <c:if test="${endIdx} < ${total}"> <html:submit property="submit">Next</html:submit> </c:if> </td> Not pretty, but it works (until $total > 99). $size = 15 if the output reads 1 to 15 of 75, the Next button shows up. if the output reads 1 to 15 of 105, the Next button doesn't show up. What I'm thinking is the problem here is that the JSTL c:if statement is comparing the values in the $vars as strings, not numbers. Because of this, my $endIndex < $total if statement is failing because 15 < 105 is false. If I could somehow compare the values as numbers, I would be ok, otherwise I think I have to left pad with zeros the variables to some fixed length before comparing them to one another. What do you think of this? Is there a better way with JSTL. I'm pretty new to this stuff.
|
 |
Miki Italiano
Greenhorn
Joined: Mar 07, 2004
Posts: 7
|
|
Adding "+0" to endIdx and total fixes the problem. It makes the auto type coersion think we're dealing with numbers again. Is there a better way? <c:if test="${(endIdx+0) < (total+0)}"> <html:submit property="submit">Next</html:submit> </c:if>
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56157
|
|
I have no way of testing this supposition where I am, but I suspect the problem stems from your initial declaration of which probably sets up endIdx as an empty string, I'd try setting its initial value to zero. [ March 27, 2004: Message edited by: Bear Bibeault ]
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
 |
I agree. Here's the link: jrebel
|
|
subject: JSTL and c:if problem
|
|
|