How to show JSF components if list is not null and has size() > 0

倾然丶 夕夏残阳落幕 提交于 2019-12-03 16:55:54

问题


How do I show JSF components if a list is not null and it has a size() > 0?


回答1:


EL offers the empty operator which checks both the nullness and emptiness of an object.

Thus, this should do:

<h:dataTable value="#{bean.list}" var="item" rendered="#{not empty bean.list}">

No need for a clumsy double check on both null and size() as suggested by other answers.

See also:

  • How do I display a message if a jsf datatable is empty?
  • Conditionally displaying JSF components



回答2:


use rendered attribute. most of the components have this attribute.This attribute;s main purpose is to render components conditionally.

<h:dataTable value="#{bean.list}" rendered="{bean.list !=null &amp;&amp; bean.list.size()>0}" >

In the above piece of jsf code, datatable would only be rendered when list is not null and the size of list is greater than 0




回答3:


<h:outputText value="No Data to Display!" rendered="#{empty list1.List2}" />
<a href="#">
<h:outputText value="Data is present" rendered="#{not empty list1.List2}" /></a>

Or

<h:outputText value="#{not empty list1.List2 ? 'Data is Present' : 'No Data to Display'}" style="color:blue"/>


来源:https://stackoverflow.com/questions/16360687/how-to-show-jsf-components-if-list-is-not-null-and-has-size-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!