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

