Search code examples
jspjstleljstl-functions

JSP String to Long exception


I have a code in JSP as follows

<td class=odd
    style="text-align: center"
    height=30><c:if
        test="${mMap['GENERAL'].errorFac != 0 and not empty mMap['GENERAL'].errorFac}">
<c:choose>  
<c:when test="${mMap['GENERAL'].errorFlag == true}">                                                    
    <A style="font-size:9pt" href="javascript:openWindow('${m.eTax}','${m.eDate}','GENERAL')" >
    <fmt:formatNumber
            value="${mMap['GENERAL'].errorFac}"
            type="number" pattern="#,##0.0000" /></A>
    </c:when>
    <c:otherwise>
    <fmt:formatNumber
            value="${mMap['GENERAL'].errorFac}"
            type="number" pattern="#,##0.0000" />
    </c:otherwise>
    </c:choose>     
    </c:if>
</td>

When the jsp is called I am getting foll. error in console:

[5/3/17 10:13:14:025 EDT] 00000253 SystemErr     R Caused by: javax.el.ELException: Cannot convert 2.34 of type class java.lang.String to class java.lang.Long
[5/3/17 10:13:14:025 EDT] 00000253 SystemErr     R  at org.apache.el.lang.ELSupport.coerceToNumber(ELSupport.java:497)
[5/3/17 10:13:14:025 EDT] 00000253 SystemErr     R  at org.apache.el.lang.ELSupport.coerceToNumber(ELSupport.java:476)
[5/3/17 10:13:14:025 EDT] 00000253 SystemErr     R  at org.apache.el.lang.ELSupport.equals(ELSupport.java:229)
[5/3/17 10:13:14:025 EDT] 00000253 SystemErr     R  at org.apache.el.parser.AstNotEqual.getValue(AstNotEqual.java:39)
[5/3/17 10:13:14:025 EDT] 00000253 SystemErr     R  at org.apache.el.parser.AstAnd.getValue(AstAnd.java:37)
[5/3/17 10:13:14:025 EDT] 00000253 SystemErr     R  at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)

Value 2.34 is the value of errorFac which come as a path variable and is a String. I am assuming the c:if is causing the issue. Any inputs please.


Solution

  • Based on this post

    String to long comparison

    you need compare String to String and zero is an Integer, so:

    <c:if test="${mMap['GENERAL'].errorFac != '0' and not empty mMap['GENERAL'].errorFac}">