JSF sort table with Ajax

Here is an example of sorting a table with ajax. I’m using using a generic comparator which I implmented a while ago to sort the list items, it saves me few lines of code actually.
If you are intrested in the generic comparator

Model

Product.java

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

publicclassProduct{

privateintid;

privateStringname;

privatedoubleprice;

publicProduct(intid,Stringname,doubleprice){

this.id=id;

this.name=name;

this.price=price;

}

publicvoidsetId(intid){

this.id=id;

}

publicvoidsetName(Stringname){

this.name=name;

}

publicvoidsetPrice(doubleprice){

this.price=price;

}

publicintgetId(){

returnid;

}

publicdoublegetPrice(){

returnprice;

}

publicStringgetName(){

returnname;

}

}

Controller

Be sure to use the new annotations(CDI) for sessionscoped,old ones will be deprecated with the next version of jsf

First we populate the list with some test data

I use datamodel as container for items nad get the list of items from it