How do you call List.size() from a JSF 2.0 Facelets Template?

早过忘川 提交于 2019-12-10 12:44:37

问题


What is the syntax for calling list.size() in a JSF 2.0 Facelets template (eg, using an h:outputText element)?


回答1:


How about this:

<h:outputText value="#{fn:length(someBean.someList)}" />

You'll need to reference the functions taglib in your JSF page (URI: http://java.sun.com/jsp/jstl/functions).




回答2:


Just try #{myBean.myList.size()}




回答3:


It's not a problem with JSF 2.0 exactly. The JSF spec still requires a class that conforms to the bean spec. The collection classes don't do that with the .size() method. It would still have to be .getSize(). Given the need for a "standard" way to access the class values, we're not getting around that in JSF any time soon. Somebody needs to fix the collection classes.




回答4:


Note: The exact namespace for "fn" is added like this:

<html xmlns="http://www.w3.org/1999/xhtml"
      ...
      xmlns:fn="http://java.sun.com/jsp/jstl/functions">


来源:https://stackoverflow.com/questions/1332169/how-do-you-call-list-size-from-a-jsf-2-0-facelets-template

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