在JSP / JSTL / EL中访问集合的大小 [英] Access the size of a collection in JSP/JSTL/EL

查看:91
本文介绍了在JSP / JSTL / EL中访问集合的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的JSP页面中有一个名为 services 的List变量。如果列表中有超过1个元素,我需要在页面中添加一些标记。

I have a List variable called services in my JSP page. I need to add some markup to the page if there's more than 1 element in the list.

我想做的是......

What I'd like to do is...

<c:if test="${services.size() gt 1}">
  <!-- markup... -->
</c:if>

但你不能在EL上调用Java对象的方法(我想这可能是364823782时间我后悔这个事实)。您只能通过删除'get'来访问Java对象上的 getters ,例如$ {user.name}用于具有getName()方法的User类。

But you can't invoke methods on Java objects in EL (I think this is perhaps the 364823782 time I've regretted that fact). You can only access getters on Java objects by dropping the 'get,' e.g. ${user.name} for a User class that has a getName() method.

评估此测试的正确方法是什么?

What's the right way to evaluate this test?

推荐答案

您正在寻找 fn:length(services)。记得定义fn名称空间。

You are looking for fn:length(services). Remember to define the fn namespace.

http://download.oracle.com/javaee/5/tutorial/doc/bnalg.html

这篇关于在JSP / JSTL / EL中访问集合的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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