-2

I've got datatable on page that query from DB. Execution time is too slow. The page takes too much time to render. How to speed it up? Stored procedures aren't a desirable solution.

<p:dataTable var="abc" value="#{abc.getValues()}">...

getValues(){
return ...createQuery(query);
}
hippietrail
  • 15,848
  • 18
  • 99
  • 158
gohohgle
  • 349
  • 1
  • 3
  • 10
  • Related: http://stackoverflow.com/questions/2090033/why-jsf-calls-getters-multiple-times/2090062#2090062 – BalusC Nov 29 '12 at 11:40

1 Answers1

2

Performing DB queries (or any heavy processing) in the getter methods that are triggered by JSF is a bad idea. If you put a logging statement in the getValues method, you will probably see that it is being called several times. Because of that, getters should be just getters and the data should be preloaded.

I see that you are using Primefaces. It brings a great facility to do exactly that - the LazyDataModel. Take a look at the according showcase. Starting with Primefaces 3.4, you can bind the dataTable to a caching field of the LazyDataModel.

kostja
  • 60,521
  • 48
  • 179
  • 224