gpt4 book ai didi

jsf - EL 空运算符在 JSF 中如何工作?

转载 作者:行者123 更新时间:2023-12-01 19:33:28 25 4
gpt4 key购买 nike

在 JSF 中,可以使用 EL 空运算符来呈现或不呈现组件

rendered="#{not empty myBean.myList}"

据我了解,该运算符既可以用作空检查,也可以检查列表是否为空。

我想对我自己的自定义类的某些对象进行空检查,我需要实现哪些接口(interface)或部分接口(interface)?空运算符与哪个接口(interface)兼容?

最佳答案

来自EL 5.0 specification :

1.11 Empty Operator - empty A

The empty operator is a prefix operator that can be used to determine if a value isnull or empty.

To evaluate empty A

  • If A is null, return true
  • Otherwise, if A is the empty string, then return true
  • Otherwise, if A is an empty array, then return true
  • Otherwise, if A is an empty Map, return true
  • Otherwise, if A is an empty Collection, return true
  • Otherwise return false

因此,考虑到接口(interface),它适用于 CollectionMap仅有的。就您而言,我认为 Collection 是最好的选择。或者,如果它是一个类似 Javabean 的对象,则使用 Map。不管怎样,在幕后,isEmpty()方法用于实际检查。对于您不能或不想实现的接口(interface)方法,您可以抛出 UnsupportedOperationException

关于jsf - EL 空运算符在 JSF 中如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14185031/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com