开发者

Beans, Lists and JSP

开发者 https://www.devze.com 2022-12-28 19:07 出处:网络
I have a little question... On my JSP page I have a List of beans. I want to extract a sublist of beans with a specific property (Ex. all Horror books). Can Apache Beanutils help me?

I have a little question...

On my JSP page I have a List of beans. I want to extract a sublist of beans with a specific property (Ex. all Horror books). Can Apache Beanutils help me?

Thanks in advance..开发者_运维技巧.


In a JSP you have 2 options:

  1. Iterate over list yourself using JSTL <c:forEach> and test using JSTL <c:if> if the item matches the requirements and finally just display it.

  2. Do the same in plain Java code and call this in a servlet prior to forwarding the request to the JSP. Optionally you can wrap this in an EL function so that you can call it from inside a JSP.

The Commons Beanutils can't help much here. It has as far as I know no collection filter with a predicate. The Commons Collections and Google Collections however have.

0

精彩评论

暂无评论...
验证码 换一张
取 消