JSTL, Beans, and method calls

那年仲夏 提交于 2019-12-03 10:43:36

When using the dot operator for property access in JSTL, ${pageDividers.size} (no () needed) results in a call to a method named getSize().
Since java.util.List offers a method called size() (rather than getSize()) you won't be able to access the list length by using that code.


In order to access to a list size, JSTL offers the fn:length function, used like

${fn:length(pageDividers)}

Note that in order to use the fn namespace, you should declare it as follows

<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

In addition, the same function can be used with any collection type, and with Strings too.

To access the property of a bean using EL you simply name the property (not invoke the method). So lets say you have a method called getSize() in the bean then

${pageDividers.size}

Notice no ().

EDIT:Sorry...made an error in the original post.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!