jspjstljstl-functions

Why can't we use JSTL fn tags independently, just like core tags


If functions tag library are also part of JSTL then why can't (or don't) we use them like other tags? For example, with core we can say something like this?

<c:if test="1==1">
    <h3>Render this if 1==1</h3>
 </c>

Why can't we do the same thing with functions, like this?

<fn:...

Can we use them inside ${} only?


Solution

  • You've got it right. JSTL functions (fn) can only be used inside ${ } because it affects or results the value of a variable. For example, if I want to know the size of an array named 'array'

    <c:out value="${fn:length(array)}" />
    

    With JSTL tags like <c:xxx ... /> you process and define variables. Inside ${ } you handle the value of a variable