Caching JSF Dropdown Results

I have following dropdown

Code:

<h:panelGrid columns="3" styleClass="detail" columnClasses="label">

<h:outputText value="Manufacturer" />

<h:selectOneMenu id="manufList" value="#{manufacturerBean.selectedManufacturer}" >

<f:selectItem itemLabel="New" itemValue="New" />

<f:selectItems value="#{manufacturerBean.manufacturerList}" />

<a4j:support action="#{manufacturerBean.loadManufacturerDetails}" event="onchange" reRender="manufName,manufDescription,manufSource,btnSave,btnDelete" />

</h:selectOneMenu>

</h:panelGrid>

The perfomance issue is Whenever i pick a value from the dropdown it results in 3 database calls

Here is the sequence of method calls

- First time the method in f:selectItems gets called which results in a database call

<f:selectItems value="#{manufacturerBean.manufacturerList}" />

- Second time as expected/desired Ajax4JSF onchange event action method gets called

<a4j:support action="#{manufacturerBean.loadManufacturerDetails}" event="onchange" reRender="manufName,manufDescription,manufSource,btnSave,btnDelete" />

- Third time again the method in f:selectItems gets called which results in a database call

<f:selectItems value="#{manufacturerBean.manufacturerList}" />

I understand its due to JSF Lifcycle.

Any pointers/suggestion on how to Cache the method getManufacturerList() to avoid unnecessary database calls will be highly appreciated

Regards

Bansi

[1598 byte] By [mail2bansia] at [2007-11-27 5:17:31]
# 1
Maintain the list in a session scoped backing bean?
BalusCa at 2007-7-12 10:40:21 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Thanks for quick response. The List is in a session scoped backing bean. But still it doesnt avoid unnecessary calls to database.
mail2bansia at 2007-7-12 10:40:21 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Maybe you need to rearrange the data loading logic. At least invoke the loading logic in the constructor or an initialization block of the backing bean.
BalusCa at 2007-7-12 10:40:21 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

u can do in one way, use IBM JSF .jar file,

<%@taglib uri="http://www.ibm.com/jsf/html_extended" prefix="hx"%>

and use <hx:scriptCollector preRender="#{yourBean.onPageLoadBegin}" />,

so when your page load it will call that method which load onces, and using flag, u can control the loading data again from back end .

I hope it will help,

Thanks

Srikanth

srikanthga at 2007-7-12 10:40:21 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
This is not freely available (at least, I read nowhere that he is using WSAD/RAD) and there are better ways than using those nasty IBM components.
BalusCa at 2007-7-12 10:40:21 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...