Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

JSTL and c:if problem

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
Sheriff
Posts: 67636
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Be reasonable. You can't destroy everything. Where would you sit? How would you read a tiny ad?
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic