Sorting is not working in datatable in PrimeFaces. Please suggest.
See below my .xhtml file
My Service had:
public List<PlayerEntity> getAllPlayers() {
return playerDao.readAll();
}
but that was wrong, because when I was calling getAllPlayers() from table
<p:dataTable id="data" value="#{myBean.allPlayers}"/>
I got from DAO refreshed data but still unordered. Instead of that I've created List field and method to update the List
private List<PlayerEntity> allPlayers = new ArrayList<PlayerEntity>();
public void updateAllPlayers(){
this.allPlayers = playerDao.readAll();
}
which method I'm running on bean initialization
public void setPlayerDao(PlayerDao playerDao) {
this.playerDao = playerDao;
updateAllPlayers();
}
and after Add, Delete or Modiffy the List
public boolean createPlayer(PlayerEntity playerEntity) {
(...)
updateAllPlayers();
return true;
}
Now my Service has
public List<PlayerEntity> getAllPlayers() {
return this.allPlayers;
}
and that solved my problem with sorting data in Primefaces table.