When I write Java webapps, I usually use JSTL tags. I think that these tags are great, except for one thing that pisses me off: while the expression language allow you to access bean properties, it does not allow you to call its methods.
In release 1.0, it was not even possible to obtain the length of a string or the number of elements in a collection. As of release 1.1, the fn:length function has been added, so you can do things such as this:
...
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
...
<c:if test="${fn:length(str) > 10}">
...
</c:if>
...
Which is more verbose and more ugly (IMHO that is) than:
...
<c:if test="${str.length() > 10}">
...
</c:if>
...
It seams that JSTL 2.0 will allow you to define new functions, but you will need to write a class specifically for that purpose, in which you will define your (static) methods, and you will also need to write a TLD file that will be included in every jsp that will use these functions.
Whether you define custom function or you use another workaround, you have a lot of additional code to write.
I have read somewhere that the JCP had voluntarily disallow the calling of methods from the expression language.
Can anyone of you help me understand why the hell is the JCP doing this to us?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…