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.
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.
Joined: Jul 03, 2008
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.