tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "...." <cekvenich_...@basebeans.com>
Subject Re: How to cast String to Number in JSTL EL ?
Date Sat, 03 Jan 2004 23:13:48 GMT
For paging, take a look at the displaytag on sf.net.

.V

Jason Lea wrote:
> I had a similar problem (paging and JSTL) and managed to get it 
> working.  The <c:set var="lastPageNo" value="1"/> code is setting the 
> lastPageNo to a string and then later on it is doing a string 
> concatenation on it so you get "13" instead of "4"
> 
> JSTL will coerce it into an integer if you assign it this way:
> 
> <c:set var="lastPageNo" value="${1}"/>
> 
> According to the JSTL spec any value="sometext" will always be a 
> string.  Using the ${} makes JSTL evaluate it and decide you have an 
> integer there.
> 
> 
> Francois Beausoleil wrote:
> 
>> Hi !
>>
>> I have a slight problem.  I am building a paged results browser, and I
>> have a problem with my next action.
>>
>> The root of the problem is because JSTL thinks that some values are
>> strings, and not numbers.
>>
>> The code I am running is:
>> <fmt:formatNumber var="lastPageNo" value="${numberOfContacts / count}"
>>        minFractionDigits="0" maxFractionDigits="0"/>
>> <c:if test="${numberOfContacts le count}">
>>    <c:set var="lastPageNo" value="1"/>
>> </c:if>
>> <c:if test="${(numberOfContacts gt count) and ((numberOfContacts mod
>> count) ne 0)}">
>>    <c:set var="lastPageNo" value="${lastPageNo + 1}"/>
>> </c:if>
>>
>>    pageNo:                <c:out value="${pageNo}"/>
>>    pageNo.class:          <c:out value="${pageNo.class}"/>
>>    lastPageNo:            <c:out value="${lastPageNo}"/>
>>    lastPageNo.class:      <c:out value="${lastPageNo.class}"/>
>>    pageNo lt lastPageNo:  <c:out value="${pageNo lt lastPageNo}"/>
>>
>> This code does arithmetics on the numbers in some cases, and when these
>> run, everything is fine.  *But*, when the arithmetic operations do not
>> run, I get the following in my comment block:
>>    pageNo:                2
>>    pageNo.class:          class java.lang.String
>>    lastPageNo:            13
>>    lastPageNo.class:      class java.lang.String
>>    pageNo lt lastPageNo:  false
>>
>> As you can see, JSTL considers both pageNo and lastPageNo to be strings.
>> I finally resolved my problem by switching to a choose, and adding an
>> otherwise block that adds 0 with lastPageNo, converting to a number.
>>
>> All of this boils down to:  is there the equivalent of a Java cast in
>> JSTL ?  If there were, I could simply cast my pageNo and lastPageNo when
>> doing my tests, and everything would be fine.
>>
>> Thanks for any help !
>> Fran├žois
>> Developer of Java Gui Builder
>> http://jgb.sourceforge.net/
>>
>> ---------------------------------------------------------------------
>> 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