This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
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


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Datatable Question" Watch "Datatable Question" New topic
Author

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Datatable Question