It's not a direct answer to your question, but it seems like the work you're doing is more suited to a servlet or component of an MVC/Model 2 framework. In other words, calculate the actual values you need before forwarding to the JSP.

AFAIK, JSTL doesn't directly support what you're looking for. When necessary, it performs automatic data conversions to make it easier to match application data with the expected types of things like tag/action attributes. Again, if possible, I'd pull your calculations out of the JSP altogether...

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/

-- Kris Schneider <mailto:[EMAIL PROTECTED]> D.O.Tech <http://www.dotech.com/>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to