Java 您如何从 JSF 2.0 Facelets 模板调用 List.size()?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1332169/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 08:20:58  来源:igfitidea点击:

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

javajsffaceletsjava-ee-6

提问by jsight

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

在 JSF 2.0 Facelets 模板中调用 list.size() 的语法是什么(例如,使用 h:outputText 元素)?

采纳答案by harto

How about this:

这个怎么样:

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

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

您需要functions在 JSF 页面(URI: http://java.sun.com/jsp/jstl/functions)中引用taglib 。

回答by Jim Barrows

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.

这完全不是 JSF 2.0 的问题。JSF 规范仍然需要一个符合 bean 规范的类。集合类不使用该.size()方法执行此操作。它仍然必须是.getSize()。鉴于需要一种“标准”方式来访问类值,我们不会很快在 JSF 中解决这个问题。有人需要修复集合类。

回答by André

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

你试一试 #{myBean.myList.size()}

回答by Benny Neugebauer

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

注意:“fn”的确切命名空间添加如下:

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