There seems to be no way to use an integer value in jsp jstl:
I tryed this:
<c:set var="numpages" value="${numrows / 5}" />
<c:choose>
<c:when test="${numrows < 6}">
${numpages} = 1
</c:when>
<c:otherwise>
<c:choose>
<c:when test="${numpages * 5 == numrows}">
${numpages} = ${numpages}
</c:when>
<c:when test="${numpages * 5 > numrows}">
${numpages} = ${numpages + 1}
</c:when>
</c:choose>
</c:otherwise>
</c:choose>
<fmt:parseNumber value="${numpages}" integerOnly="true" />
number of pages = ${numpages} THIS LINE ONLY TO SEE WHAT WAS CALCULATED.
But I still get a decimal i.e., 14.72
I finally had to use a bean to do what I needed. Here is what I had to do.
By the way this is code to calculate pagination.
First I get the number of rows from database:
<sql:query var="usercount"
sql='Select count(petid) as kpetid from pets'>
</sql:query>
<c:forEach items="${usercount.rows}" var="count">
<c:set var="numrows" value="${count.kpetid}" />
</c:forEach>
number of rows = <c:out value="${numrows}"/>
next set bean property:
<jsp:setProperty
name="db"
property="numpages"
value="${numrows}" />
number pages = ${db.numpages} THIS LINE IS TEMPERORY TO TEST RESULTS I GET 15 WHICH IS CORRECT
And in bean:
public void setnumpages(int numrows)
{
this.numpages = numrows / 5;
if (this.numpages < 6)
{
this.numpages = 1;
}
else
{
if ((this.numpages * 5) == numrows)
{
this.numpages = numrows / 5;
}
else
{
this.numpages = (this.numpages) + 1;
}
}
} // THIS ABSOLUTLY WORKS WITH ZERO PROBLEMS
public int getnumpages()
{
return (this.numpages);
}
Because in a bean you can declare int.
Ok my question, how do I do this in jstl? AND, the <c:choose> tag prints out results. I need the caculations, but not printed to the webpage. AND only deal with integers.
I have googled this, but no answer found.