I write a JSF 2 page which visualizes data from database.
When I use Primefaces datatable with ViewScoped or RequestScoped bean getting values from a database it doesn't work properly - doesn't sort and doesn't paginate. For example:
@ManagedBean
@ViewScoped
public class MyBean implements Serializable {
private List<Animal> animals;
public List<Animal> getAnimals() {
if(animals == null) {
animals = DataBaseConnector.getLastAnimals();
}
return animals;
}
}
When I change ViewScoped with SessionScoped it works well, but I want to use it with RequestScope and ViewScope. When I use the same bean with adding static values like here:
@ManagedBean
@ViewScoped
public class MyBean implements Serializable {
private List<Animal> animals = new ArrayList<Animal>() {{
add(new Animal("John", 7, new Timestamp(2436343516841235621L)));
add(new Animal("Holly ", 15, new Timestamp(52343332153212142L)));
add(new Animal("Betty", 3, new Timestamp(2346236232151232L)));
}};
public List<Animal> getAnimals() {
return animals;
}
}
It works properly - it sorts and paginates. Can I use primefaces datatable with RequestScoped bean getting values from database?