wood burning stoves 2.0*
The moose likes JSF and the fly likes Datatable Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Datatable Question" Watch "Datatable Question" New topic

Datatable Question

Andy Holm
Ranch Hand

Joined: Jul 03, 2008
Posts: 86
I have a JSF datatable that has its value backed to an arraylist on my backing bean. Normally, the method to retrieve the value from my backing bean gets called during two different phases. Is there anyway to prevent this from hitting the database during the APPLY_REQUEST_VALUES phase? This seems like a performance nightmare. I am using request scoped beans and don't want to switch to session scoped beans.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Getters are there to return bean properties and not to do some business/database logic. Getters can be called more than once in bean's life. Move the data loading logic to the constructor or initialization block of the bean. Or if you really, really want to do it in the getter, then introduce lazy loading.
Andy Holm
Ranch Hand

Joined: Jul 03, 2008
Posts: 86
I initially was doing the lazy loading solution, but I ran into a problem when my other business logic threw an error and the page containing the datatable was reloaded to show the FacesMessages. When this happened, the call to the database retrieved the wrong data because it was first run during the APPLY_REQUEST_VALUES phase before the query request parameters were applied to the proper bean. When the getter was called again in the RENDER_RESPONSE phase, the lazy load prevented the database from being queried with the correct parameters, which had now been populated on the proper bean.
It is sorta covered in the JavaRanch Style Guide.
subject: Datatable Question
Similar Threads
Bean from Bean
Session-scoped Backing Bean
Multiple selectOneMenu with same value
DynaFaces and commandLinks
selectmanycheckbox with selectitem