java JSF - 在单一方法中检查 null 和 empty

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

JSF - checking null and empty in single method

javajsf

提问by Ketan

Currently my code is like

目前我的代码就像

<h:panelGroup rendered="#{templatePrescriptionMaintenanceBackingBean.allSelectedMedicationList != null && !empty templatePrescriptionMaintenanceBackingBean.allSelectedMedicationList}">
        <b>List of Selected Drugs</b> // and some other stuff
</h:panelGroup> 

Now allSelectedMedicationListwill do lot of process in backend. Calling webservice and adding data in current DB and so on...

现在allSelectedMedicationList将在后端做很多处理。调用 webservice 并在当前数据库中添加数据等等...

Now issue arise when I need to check nullor empty- 2 timesthat method called here. Once again when I use same method with datatable it will call again 1 moretime. I think to create one method or something for JSF it self that will check nulland emptyat same time and return list. Is it possible?

现在,当我需要检查nullempty-此处调用该方法的2 次时出现问题。再一次,当我对数据表使用相同的方法时,它会再调用1次。我想为 JSF 自己创建一种方法或其他东西,它会检查nullempty同时返回列表。是否可以?

回答by Pablo

The operator "empty" already does what you want, you don't need to also check null.

运算符“空”已经做了你想要的,你不需要也检查空。

From http://docs.oracle.com/javaee/5/tutorial/doc/bnahq.html#bnaik:

来自http://docs.oracle.com/javaee/5/tutorial/doc/bnahq.html#bnaik

Empty: The empty operator is a prefix operation that can be used to determine whether a value is null or empty.

Empty:空操作符是一个前缀操作,可用于确定一个值是空值还是空值。