I am using the following conditional check using JSTL but its throwing the error “javax.servlet.jsp.el.ELException: No function is mapped to the name “fn:length”
<c:choose>
<c:when test='${fn:length(studentData.rollNumber) == "0"}'>
Found Nothing
</c:when>
<c:otherwise>
Found something
</c:otherwise>
</c:choose>
What am I doing wrong here? I just need to compare the length of roll number.
As per the documentation, the
fn:length()only works onString(which would return the value ofString#length()method) and onCollection(which would return the value ofCollection#size()method).You however seem to be passing in a number. An integer or something. The
fn:length()doesn’t work on numbers and would always givefalse, irrespective of the number’s value.If you want to check if something is
null, then just do so:Or if you want to check if the number’s value is
0, then just doNote that the
emptycheck works equally well and this is regardless of whether it’s a number, string or a collection. Anything which isnullor has afn:length()of0would evaluatetrue.