Let's
suppose that you have the following bean content:
@Named
@SessionScoped
public class
PlayerBean implements Serializable {
private Map<Integer, String> atp =
new HashMap<>();
private String player;
public PlayerBean() {
atp.put(1, "Rafael Nadal");
atp.put(2, "Novak Djokovic");
atp.put(3, "Roger Federer");
atp.put(4, "Andy Murray");
atp.put(5, "David Ferrer");
}
public String playerByRank(int rank) {
return "Number " + rank +
" in ATP is: " + atp.get(rank);
}
}
Now, we
simply want to display on screen the ATP player for rank 4. Without any fancy
workarounds, we can exploit parameterized EL, as below (no forms, no
getters/setters):
<h:body>
<h:outputText
value="#{playerBean.playerByRank(4)}"/>
#{playerBean.playerByRank(4)}
</h:body>
Output on
screen:
Number 4 in
ATP is: Andy Murray
Number 4 in
ATP is: Andy Murray
Niciun comentariu :
Trimiteți un comentariu