EL空运算符如何在JSF中工作? [英] How does EL empty operator work in JSF?

查看:90
本文介绍了EL空运算符如何在JSF中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In JSF an component can be rendered or not using the EL empty operator

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

据我所知,运算符既可以作为null检查,也可以检查列表是否为空.

As I've understood the operator works both as null-check, but also check checks if the list is empty.

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

I want to do empty checks on some objects of my own custom class, which interface(s) or parts of interfaces do I need to implement? Which interface is the empty operator compatible with?

推荐答案

来自 EL 2.2规范(在点击此处下载评估规范"下面获得一个):

From EL 2.2 specification (get the one below "Click here to download the spec for evaluation"):

1.10空运算符-empty A

empty运算符是前缀运算符,可用于确定值是否为 空或空.

1.10 Empty Operator - empty A

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

要评估empty A

  • 如果Anull,则返回true
  • 否则,如果A是空字符串,则返回true
  • 否则,如果A是一个空数组,则返回true
  • 否则,如果A为空的Map,则返回true
  • 否则,如果A为空的Collection,则返回true
  • 否则返回false
  • 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

因此,考虑到接口,它可以在 Collection Map .就您而言,我认为Collection是最佳选择.或者,如果它是类似Javabean的对象,则Map.无论哪种方式, isEmpty() 方法用于实际检查.在您无法或不想实现的接口方法上,可以抛出UnsupportedOperationException.

So, considering the interfaces, it works on Collection and Map only. In your case, I think Collection is the best option. Or, if it's a Javabean-like object, then Map. Either way, under the covers, the isEmpty() method is used for the actual check. On interface methods which you can't or don't want to implement, you could throw UnsupportedOperationException.

这篇关于EL空运算符如何在JSF中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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