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

el, if-statement, jsf

Solution

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

Problem

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

Original source

Related problems