Also i recall your suggestion to cache the getManufacturerList() method in
backing bean using RequestMap . I apologize i didnt understood that how this
would eliminate unnecessary database calls but still ended developing
following snippet in backing bean which results in Null Pointer Exception
public List getManufacturerList()
{
Map reqMap =
FacesContext.getCurrentInstance().getExternalContext().getRequestMap();
//Map reqMap =
FacesContext.getDefaultInstance().getExternalContext().getRequestMap();
System.out.println("Map Size="+reqMap.size());
List<SelectItem> manufacturerList =
(List<SelectItem>)reqMap.get(manufacturerList_KEY);
System.out.println("manufacturerList="+manufacturerList.size());
List<NamsManufacturer> manufResultSet = new ArrayList<NamsManufacturer>();
if (manufacturerList == null)
{
// TODO: load it
manufResultSet = manufManager.getManufacturerList();
System.out.println(" *** From Database manuf List Size=***
"+manufResultSet.size());
for (int i=0; i< manufResultSet.size(); i++) {
NamsManufacturer namsManufacturer = (NamsManufacturer)
manufResultSet.get(i);
//System.out.println("ID: " + namsManufacturer.getId());
//System.out.println("NAME: " +
namsManufacturer.getName());
Long manufId = namsManufacturer.getId();
String manufName = namsManufacturer.getName();
manufacturerList.add(new
SelectItem(manufId.toString(),manufName));
}
reqMap.put(manufacturerList_KEY, manufacturerList);
}
return manufacturerList;
}
Could you please elaborate on how using RequestMap would eliminate
unnecessary database calls and how do i refine the above method to cache the
results
Regards
Bansi
Andrew Robinson-5 wrote:
>
> How about <t:saveState value="#{manufacturerBean.manufacturerList}"
> />? If you are using a4j:region, you will need to make sure the save
> state tag in in the region (BTW - I haven't tested this).
>
> On 5/23/07, bansi <[EMAIL PROTECTED]> wrote:
>>
>> 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 datbase 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
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Caching-JSF-Dropdown-Results-tf3805830.html#a10770409
>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>
>>
>
>
--
View this message in context:
http://www.nabble.com/Caching-JSF-Dropdown-Results-tf3805830.html#a10772148
Sent from the MyFaces - Users mailing list archive at Nabble.com.