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

vineri, 2 octombrie 2015

[OmniFaces utilities 2.0] Create an integer array which starts/ends at the given integers, inclusive


[OmniFaces utilities] The createIntegerArray() function creates and return an integer array which starts at the given integer and ends at the given integer, inclusive. This is useful if you want to for example populate a <f:selectItems> which shows an integer range to represent days and years. If the begin is greater than end, then the array will be decremental. If the begin equals end, then the array will contain only one item.

Function:
Usage:

Below you can see a two simple examples of using the of:createIntegerArray() function:

// create an integer array from 10 to 20
<ui:repeat value="#{of:createIntegerArray(10, 20)}" var="i" varStatus="loop">
 #{i}#{!loop.last ? ', ' : ''}
</ui:repeat>

Output: 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20

// create another dummy array of size 5
<table border="1">
 <tr>
  <td>Value</td>
  <td>Index</td>
  <td>First</td>
  <td>Last</td>
  <td>Begin</td>
  <td>End</td>
  <td>Step</td>
  <td>Current</td>
  <td>Even</td>
  <td>Odd</td>
 </tr>          
 <ui:repeat value="#{of:createIntegerArray(10, 20)}" var="i" varStatus="vs">         
  <tr>
   <td>#{i}</td>
   <td> #{vs.index}</td>
   <td>#{vs.first}</td>
   <td>#{vs.last}</td>
   <td>#{vs.begin}</td>
   <td>#{vs.end}</td>
   <td>#{vs.step}</td>
   <td>#{vs.current}</td>
   <td>#{vs.even}</td>
   <td>#{vs.odd}</td>
  </tr>          
 </ui:repeat>
</table>

Output:

This is useful if you want to for example populate a <f:selectItems> which shows an integer range to represent days and years. If the begin is greater than end, then the array will be decremental. If the begin equals end, then the array will contain only one item. For such an example, ckeck OmniFaces Showcase.

Niciun comentariu :

Trimiteți un comentariu

JSF BOOKS COLLECTION

Postări populare

OmniFaces/JSF Fans

Follow by Email

Visitors Starting 4 September 2015

Locations of Site Visitors