开发者

Difference between LENGTH[...] and fn:length(...) in JSP EL

What is the difference between the LENGTH[...] and the JSTL function fn:length(...)?

I tr开发者_如何学Pythonied to search to difference but I did not see any example that uses the first one.

Here is an example:

<c:when test="${object.field ne null || LENGTH[object.field] > 0}"> 
    <td valign="top">
        .....print something
    </td>
</c:when>


Since there is no such function like LENGTH[...] in standard JSP/JSTL/EL, it's impossible to tell about the differences. The fn:length() is the only way to obtain the length of a String, an Object[] or Collection.

${fn:length(someCollection)}

Update as per your (fixed) example:

<c:when test="${object.field ne null || LENGTH[object.field] > 0}"> 

I've never seen this before. It look like that your webapp/servletcontainer is using a custom EL resolver. If this is true, you should see it been declared in webapp's web.xml file.

Regardless, you'd rather like to use the EL empty keyword here. It not only checks for null, but also for the length of the String, Object[] or Collection.

<c:when test="${not empty object.field}"> 

No need for fn:length() here.


The brace notation [] is in turn by the way often used to access properties by dynamic keys. E.g.

${bean[propertyname]}

If propertyname resolves to "foo", then the above does effectively the same as ${bean.foo}. It's also often used on Map objects in the scope.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜