My JSF Books/Videos My JSF Tutorials OmniFaces/JSF PPTs
JSF 2.3 Tutorial
JSF Caching Tutorial
JSF Navigation Tutorial
JSF Scopes Tutorial
JSF Page Author Beginner's Guide
OmniFaces 2.3 Tutorial Examples
OmniFaces 2.2 Tutorial Examples
JSF Events Tutorial
OmniFaces Callbacks Usages
JSF State Tutorial
JSF and Design Patterns
JSF 2.3 New Features (2.3-m04)
Introduction to OmniFaces
25+ Reasons to use OmniFaces in JSF
OmniFaces Validators
OmniFaces Converters
JSF Design Patterns
Mastering OmniFaces
Reusable and less-verbose JSF code

My JSF Resources ...

Java EE Guardian
Member of JCG Program
Member MVB DZone
Blog curated on ZEEF
OmniFaces is an utility library for JSF, including PrimeFaces, RichFaces, ICEfaces ...

.

.

.

.

.

.

.

.


[OmniFaces Utilities] - Find the right JSF OmniFaces 2 utilities methods/functions

Search on blog

Petition by Java EE Guardians

Twitter

marți, 13 octombrie 2015

[OmniFaces utilities (2.0)] Convert a Iterable<E> to a List<E>


[OmniFaces utilities] The iterableToList() function converts a Iterable<E> to a List<E>. Useful when you want to iterate over an Iterable, which includes any type of Collection (which includes e.g. a Set) in for example <ui:repeat> and <h:dataTable>.

Note When iterating specifically over a Set use Converters#setToList(Set) is an alternative to this.

Function:
Usage:

Beside the of:setToList(), OmniFaces provides a generic function for Iterables named, of:iterableToList(). This is useful when you need to iterate over an Iterable (e.g. Set), which includes any type of Collection. Especially in JSF 2.0/2.1 where <h:dataTable> and <ui:repeat> doesn't support Iterable directly. For example, via this method you can easily use #{fooBean.iterable} in <h:dataTable>:

Queue<Players> queue = new PriorityQueue<>();

<h:dataTable value="#{of:iterableToList(playersBean.queue)}" var="t">
 ...
</h:dataTable>

Starting with JSF 2.2 the <h:dataTable> support  Iterable directly, so you don't need of:iterableToList() anymore. You can simply write:

<h:dataTable value="#{playersBean.queue}" var="t">
...
</h:dataTable>

Well, <ui:repeat> still cannot directly use Iterable in JSF 2.2, so you can use of:iterableToList() or, via EL 2.2, toArray() method. Check the below examples for queue:

<ui:repeat value="#{of:iterableToList(playersBean.queue)}" var="t">
 ...
</ui:repeat>

<ui:repeat value="#{playersBean.queue.toArray()}" var="t">
 ...

Niciun comentariu :

Trimiteți un comentariu

JSF BOOKS COLLECTION

Postări populare

OmniFaces/JSF Fans

Visitors Starting 4 September 2015

Locations of Site Visitors