如何在JSF表达式语言中获得列表的长度? [英] How do you get the length of a list in the JSF expression language?

查看:127
本文介绍了如何在JSF表达式语言中获得列表的长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用JSF EL表达式获取 ArrayList 的长度?

How would I get the length of an ArrayList using a JSF EL expression?

#{MyBean.somelist.length}

不起作用。

推荐答案

是的,因为Java API创建中的一些天才委员会决定,即使某些类具有 size()成员或 length 属性,它们也不会实现 getSize() getLength()哪些JSF和大多数其他标准都需要,你不能做你想做的事。

Yes, since some genius in the Java API creation committee decided that, even though certain classes have size() members or length attributes, they won't implement getSize() or getLength() which JSF and most other standards require, you can't do what you want.

有几种方法可以做到这一点。

There's a couple ways to do this.

一:向Bean添加一个返回长度的函数: / p>

One: add a function to your Bean that returns the length:


In class MyBean:
public int getSomelistLength() { return this.somelist.length; }

In your JSF page:
#{MyBean.somelistLength}

二:如果你'使用Facelets(哦,上帝,你为什么不使用Facelets!),你可以添加fn命名空间并使用长度函数

Two: If you're using Facelets (Oh, God, why aren't you using Facelets!), you can add the fn namespace and use the length function


In JSF page:
#{ fn:length(MyBean.somelist) }

这篇关于如何在JSF表达式语言中获得列表的长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆