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


duminică, 1 noiembrie 2015

[OmniFaces utilities (2.0)] Split the given array into an array of subarrays of the given fragment size

[OmniFaces utilities] The splitArray() function splits the given array into an array of subarrays of the given fragment size. This is useful for creating nested <ui:repeat> structures, for example, when positioning a list of items into a grid based layout system such as Twitter Bootstrap.


Let's suppose that we have a managed bean named ColorsBean that contains the following array of colors:

public class ColorsBean implements Serializable {

 private String[] colors = new String[9];       

 public ColorsBean() {
  colors[0] = "#045FB4";
  colors[1] = "#F781BE";
  colors[2] = "#0B3B0B";
  colors[3] = "#F7819F";
  colors[4] = "#2E2E2E";
  colors[5] = "#B40404";
  colors[6] = "#04B404";
  colors[7] = "#D0A9F5";
  colors[8] = "#FFFF00";

 public String[] getColors() {
  return colors;

 public void setColors(String[] colors) {
  this.colors = colors;

Now, as an example, we shape this array as a 3x3 table like in figure  below:

<table border="1">
 <ui:repeat value="#{of:splitArray(colorsBean.colors, 3)}" var="subArray">
   <ui:repeat value="#{subArray}" var="item">
    <td style="background-color:#{item}">#{item}</td>

Niciun comentariu :

Trimiteți un comentariu


Postări populare

OmniFaces/JSF Fans

Follow by Email

Visitors Starting 4 September 2015

Locations of Site Visitors