[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