Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 232
developer Avatar asked May 03 '13 13:05

developer


2 Answers

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
like image 182
BalusC Avatar answered Oct 18 '22 02:10

BalusC


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

like image 2
PermGenError Avatar answered Oct 18 '22 04:10

PermGenError