Need exemple JSF + Datatable
Need exemple JSF + Datatable
Hi,
i try about 2 days to make a Dynamic web projet in eclipse with jsf ( 2.2) and DataTatable. But, i dont find anay example to fill sAjaxSource correctly...
my html look like
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<h:outputStylesheet library="css" name="jquery.dataTables.css" />
<h:outputScript library="js" name="jquery-1.11.1.min.js" />
<h:outputScript library="js" name="jquery.dataTables.min.js" />
<script type="text/javascript">
$(document).ready(function() {
$('.display').dataTable( {
"bServerSide":true,
"sAjaxSource":"/PreuveConcepteDataTablesAndJsf/",
"bProcessing":true,
"sPaginationType":"full_numbers",
"bJQueryUI":true
]
} );
} );
</script>
</h:head>
<h:body>
<h2>Test</h2>
<div>
<h:dataTable id="mytable" styleClass="display" value="#{testBean.sourcesData}" var="emp">
</h:dataTable></div>
</h:body>
</html>
and my class controller :
package com.bidon.test;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import javax.annotation.Generated;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.json.*;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
@ManagedBean
@SessionScoped
public class TestBean implements Serializable {
String sourcesData;
Gson gson;
ArrayList<Employe> listeEmploye ;
public TestBean() {
super();
listeEmploye= new ArrayList<Employe>();
listeEmploye.add(new Employe("Bob","chief designer", 31));
listeEmploye.add(new Employe("Sam","designer", 34));
listeEmploye.add(new Employe("Frank","designer", 62));
listeEmploye.add(new Employe("jule","designer", 58));
listeEmploye.add(new Employe("Jo","designer", 30));
GsonBuilder builder = new GsonBuilder();
gson = builder.create();
}
public String getSourcesData()
{
return gson.toJson(listeEmploye);
}
public void setSourcesData(String sources)
{
}
public ArrayList<Employe> getListeEmploye() {
return listeEmploye;
}
public void setListeEmploye(ArrayList<Employe> listeEmploye) {
this.listeEmploye = listeEmploye;
}
public class Employe{
String name;
String position;
int age;
public Employe ( String name,String position,int age){
this.name = name;
this.position = position;
this.age = age;
}
public Employe ( ){
name="";
position="";
age =99;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPosition() {
return position;
}
public void setPosition(String position) {
this.position = position;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
}