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

Se încarcă...

Petition by Java EE Guardians


marți, 27 ianuarie 2015

[OmniFaces utilities (2.0)] Add the given data argument/arguments/mapping of data arguments to the current ajax response

[OmniFaces utilities] The data() methods add the given data argument/arguments/mapping of data arguments to the current ajax response.

Method (add argument):
Method (add arguments):
Method (add mapping of data arguments):
Usage of all three:

JSF Page: 
 <script src=""></script>
 <script type="text/javascript">
  function showData() {
   var data =;
   var $showData = $("#showData");

   $.each(data, function (key, value) {
     $("&lt;li&gt;").text(key + "=" + JSON.stringify(value)).appendTo($showData);
  <ul id="showData"></ul>
  <h:commandButton value="Show Players Data" onclick="$('#showData').empty()"
   <f:ajax />

JSF Bean:
import org.omnifaces.util.Ajax;
public class PlayersBean implements Serializable {

 private List<Players> players = new ArrayList<>();
 final SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");

 public PlayersBean() {
  try {
      players.add(new Players(2, "NOVAK DJOKOVIC", (byte) 26, "Belgrade, Serbia",
      "Monte Carlo, Monaco", (short) 188, (byte) 80, "Boris Becker, Marian Vajda",
      players.add(new Players(1, "RAFAEL NADAL", (byte) 27, "Manacor, Mallorca,
      Spain", "Manacor, Mallorca, Spain", (short) 185, (byte) 85, "Toni Nadal",
      players.add(new Players(7, "TOMAS BERDYCH", (byte) 28, "Valasske Mezirici,
      Czech", "Monte Carlo, Monaco", (short) 196, (byte) 91, "Tomas Krupa",
  } catch (ParseException ex) {
    Logger.getLogger(PlayersBean.class.getName()).log(Level.SEVERE, null, ex);

 public void showPlayers() {"First Player: ", players.get(0).getPlayer());"First Player:", players.get(0).getPlayer(),
            "Last Player", players.get(players.size() - 1).getPlayer());
  Map<String, Object> data = new HashMap<>();
  data.put("name", players.get(0).getPlayer());
  data.put("age", players.get(0).getAge());
  data.put("born", players.get(0).getBorn());
  data.put("heights", new Short[]{players.get(0).getHeight(),
    players.get(1).getHeight(), players.get(2).getHeight()});
  data.put("list", players);;



Niciun comentariu :

Trimiteți un comentariu


Postări populare

OmniFaces/JSF Fans

Follow by Email

Visitors Starting 4 September 2015

Locations of Site Visitors