[OmniFaces utilities] The
reverseArray()
function returns a copy of the array with items in reversed order.Function:
Usage:
Let's suppose that we have the following simple array defined in a bean:
@Named
@RequestScoped
public class
MonthsBean {
private String[] months = new String[]
{"January", "February", "March",
"April", "May", "June", "July",
"August", "September", "October", "November", "December"};
"August", "September", "October", "November", "December"};
public String[] getMonths() {
return
months;
}
}
Now, we can display the array as it was defined and in reverse order as below:
// as it was
defined
<ui:repeat
value="#{monthsBean.months}" var="item"
varStatus="loop">
#{loop.index + 1} : #{item} #{!loop.last ? ',
' : ''}
</ui:repeat>
Output:
Output:
1 : January , 2 : February , 3 : March , 4 : April , 5 : May , 6
: June ,
7 : July , 8 : August , 9 : September , 10 : October , 11 : November , 12 : December
7 : July , 8 : August , 9 : September , 10 : October , 11 : November , 12 : December
// reversed
(xmlns:of="http://omnifaces.org/functions")
<ui:repeat
value="#{of:reverseArray(monthsBean.months)}"
var="item" varStatus="loop">
#{loop.index + 1} : #{item} #{!loop.last ? ',
' : ''}
</ui:repeat>
Output:
Output:
1 : December , 2 : November , 3 : October , 4 : September , 5 :
August , 6 : July ,
7 : June , 8 : May , 9 : April , 10 : March , 11 : February , 12 : January
7 : June , 8 : May , 9 : April , 10 : March , 11 : February , 12 : January
Niciun comentariu :
Trimiteți un comentariu