[OmniFaces utilities] The
joinMap()
function joins all elements of the given map to a single string, separated by the given key-value pair separator and entry separatorFunction:
Usage:
Let's suppose that we have a managed bean named PlayersBean that contains the following
Map:
@Named
@ViewScoped
public class
PlayerBean implements Serializable {
private Map<String, String> players =
new HashMap<>();
public PlayerBean() {
players.put("1", "RAFAEL
NADAL");
players.put("2", "NOVAK
DJOKOVIC");
players.put("3", "STANISLAS
WAWRINKA");
players.put("4", "JUAN MARTIN
DEL POTRO");
players.put("5", "ROGER
FEDERER");
}
public Map<String, String> getPlayers()
{
return
players;
}
public void setPlayers(Map<String,
String> players) {
this.players = players;
}
}
Now, in page, we can join this Map items into a String of items delimited by comma (each key-value pair
is separated by dot), as below:
Join players:
<strong>#{of:joinMap(playerBean.players, '.', ', ')}</strong>
Outputs:
Join players: 1.RAFAEL NADAL, 2.NOVAK DJOKOVIC,
3.STANISLAS WAWRINKA, 4.JUAN MARTIN DEL POTRO, 5.ROGER FEDERER
Niciun comentariu :
Trimiteți un comentariu