list 使用 EL 获取列表或数组中的特定元素

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8637285/
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-09-11 01:45:42  来源:igfitidea点击:

Get specific element in a list or array using EL

arrayslistjakarta-eeel

提问by Sameh Farahat

Is it possible to get specific element in list or array using EL in a Java EE page (Facelets or JSP), or do I have to create a custom EL method?

是否可以在 Java EE 页面(Facelets 或 JSP)中使用 EL 获取列表或数组中的特定元素,或者我是否必须创建自定义 EL 方法?

回答by BalusC

You can use the brace notation []wherein you specify the (zero-based) index of the element you'd like to retrieve.

您可以使用大括号表示法,在[]其中指定要检索的元素的(从零开始的)索引。

<p>This is the 3rd item of the list: #{bean.list[2]}</p>

This syntax does basically the same as bean.getList().get(2).

此语法与bean.getList().get(2).

This is equivalent for arrays.

这对于数组是等价的。

<p>This is the 3rd item of the array: #{bean.array[2]}</p>

This syntax does basically the same as bean.getArray()[2].

此语法与bean.getArray()[2].

See also:

也可以看看: