You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by bansi <ma...@yahoo.com> on 2007/05/23 20:49:21 UTC

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 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.


Re: Caching JSF Dropdown Results

Posted by David Delbecq <de...@oma.be>.
Hi Bansi,
This is the third time you as the same problem about the fact list of
item is re-read from bean each time a dropdown is used. You should
probably referer to response already given to you:

http://www.nabble.com/JSF-Dropdown-Perfomance-Issues-tf3710469.html#a10378469
http://www.nabble.com/Perfomance-Issues-with-JSF-dropdown-tf3694314.html#a10330594

bansi a écrit :
> 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
>
>   

Re: Caching JSF Dropdown Results

Posted by Titi Wangsa <bl...@gmail.com>.
they are provided by spring, but i need more control, so i write my own,
hope this helps you make less trip to the db

Re: Caching JSF Dropdown Results

Posted by bansi <ma...@yahoo.com>.
Thank you so much. I really appreciate you sharing with the Forums
A little clarification though...
Are the MethodObjectCacheKeyGenerator and ValueCacheKeyGenerator built-in
classes provided by the Spring Framework OR is it something we have to write 
i am confused by the package name com.XXX

Regards
Bansi
 

Titi Wangsa wrote:
> 
> something like this for the skeleton
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns="http://www.springframework.org/schema/beans"
>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xsi:schemaLocation="
>        http://www.springframework.org/schema/beans
>        http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
>     <bean id="cacheManager"
>         class="
> org.springmodules.cache.provider.oscache.OsCacheManagerFactoryBean">
>         <property name="configLocation">
>             <value>classpath:oscache.properties</value>
>         </property>
>     </bean>
> 
>     <bean id="cacheProviderFacade"
>         class="org.springmodules.cache.provider.oscache.OsCacheFacade">
>         <property name="cacheManager" ref="cacheManager" />
>     </bean>
> 
>     <bean id="cacheProxyTemplate" abstract="true"
>         class="
> org.springmodules.cache.interceptor.proxy.CacheProxyFactoryBean">
>         <property name="cacheProviderFacade">
>             <ref local="cacheProviderFacade" />
>         </property>
>         <property name="cacheKeyGenerator">
>             <ref local="cacheKeyGenerator" />
>         </property>
>     </bean>
> 
>     <bean id="cacheKeyGenerator"
>         class="com.xxx.MethodObjectCacheKeyGenerator">
>     </bean>
>     <bean id="valueCacheKeyGenerator"
>         class="com.xxx.ValueCacheKeyGenerator">
>     </bean>
> </beans>
> 
> 
> and use it with
>     <bean id="positionVacancyDAO" parent="cacheProxyTemplate">
>         <property name="cachingModels">
>             <props>
>                 <prop key="findCompanies">refreshPeriod=300</prop>
>             </props>
>         </property>
>         <property name="target">
>             <ref local="positionVacancyDAOTarget" />
>         </property>
>     </bean>
> where the "positionVacancyDAOTarget" is you dao does the query to the
> database
> "findCompanies" is function call you want to cache the result
> and "refreshPeriod=300" means first call goes to the db, and for every
> call
> within 5 minutes (300 seconds), just use the cache.
> 
> i think ideally there is a transaction-proxied service that uses your
> cache-proxied dao and your jsf code calls the service.
> 
> i've asked the spring people about this, and they hinted that using
> hibernate and a secondary cache is better..
> 
> 

-- 
View this message in context: http://www.nabble.com/Caching-JSF-Dropdown-Results-tf3805830.html#a10793450
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: Caching JSF Dropdown Results

Posted by Titi Wangsa <bl...@gmail.com>.
something like this for the skeleton
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
       http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
    <bean id="cacheManager"
        class="
org.springmodules.cache.provider.oscache.OsCacheManagerFactoryBean">
        <property name="configLocation">
            <value>classpath:oscache.properties</value>
        </property>
    </bean>

    <bean id="cacheProviderFacade"
        class="org.springmodules.cache.provider.oscache.OsCacheFacade">
        <property name="cacheManager" ref="cacheManager" />
    </bean>

    <bean id="cacheProxyTemplate" abstract="true"
        class="
org.springmodules.cache.interceptor.proxy.CacheProxyFactoryBean">
        <property name="cacheProviderFacade">
            <ref local="cacheProviderFacade" />
        </property>
        <property name="cacheKeyGenerator">
            <ref local="cacheKeyGenerator" />
        </property>
    </bean>

    <bean id="cacheKeyGenerator"
        class="com.xxx.MethodObjectCacheKeyGenerator">
    </bean>
    <bean id="valueCacheKeyGenerator"
        class="com.xxx.ValueCacheKeyGenerator">
    </bean>
</beans>


and use it with
    <bean id="positionVacancyDAO" parent="cacheProxyTemplate">
        <property name="cachingModels">
            <props>
                <prop key="findCompanies">refreshPeriod=300</prop>
            </props>
        </property>
        <property name="target">
            <ref local="positionVacancyDAOTarget" />
        </property>
    </bean>
where the "positionVacancyDAOTarget" is you dao does the query to the
database
"findCompanies" is function call you want to cache the result
and "refreshPeriod=300" means first call goes to the db, and for every call
within 5 minutes (300 seconds), just use the cache.

i think ideally there is a transaction-proxied service that uses your
cache-proxied dao and your jsf code calls the service.

i've asked the spring people about this, and they hinted that using
hibernate and a secondary cache is better..

Re: Caching JSF Dropdown Results

Posted by bansi <ma...@yahoo.com>.
That sounds exciting. Could you please share the process/code snippets on how
to do this

Titi Wangsa wrote:
> 
> spring + spring-modules-cache + oscache.
> that's how we do it..
> no eager reading in "init" methods.
> 
> the data gets stored in the cache the first time it is read
> next read would just retrive the data from the cache
> 
> there is a setting so that you can have the cache to be considered stale
> after a certain amount of time
> 
> so you can have a list that is "no older than 1 hour" or "data as of 1:00
> pm"
> 
> 

-- 
View this message in context: http://www.nabble.com/Caching-JSF-Dropdown-Results-tf3805830.html#a10787368
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: Caching JSF Dropdown Results

Posted by Titi Wangsa <bl...@gmail.com>.
spring + spring-modules-cache + oscache.
that's how we do it..
no eager reading in "init" methods.

the data gets stored in the cache the first time it is read
next read would just retrive the data from the cache

there is a setting so that you can have the cache to be considered stale
after a certain amount of time

so you can have a list that is "no older than 1 hour" or "data as of 1:00
pm"

Re: Caching JSF Dropdown Results

Posted by bansi <ma...@yahoo.com>.
Thanks Andrew & David
I am finally able to get Cache the data & avoid unnecessary database calls .
This is what i have done

Spring Manager Bean
getManufacturerList(){
 return manufacturerCache which is Map and gets populated from the database
in init method of the bean 
} 
So everytime JSF Backing Bean calls getManufacturerList in Spring the data
is returned from the Cache.
The limitations of this approach are
- Stale data in the Cache. Any pointers/suggestions on how to refresh the
Cache will be highly appreciated
- The Cache i.e. Map datastructure has to store 1640 records which hangs the
application
 
Regards
Bansi

Andrew Robinson-5 wrote:
> 
> List<SelectItem> manufacturerList =
> (List<SelectItem>)reqMap.get(manufacturerList_KEY);
>  System.out.println("manufacturerList="+manufacturerList.size());
> 
> The println statement will throw a null pointer exception as you are
> calling "size()" on null the first time the function is called.
> 
> On 5/23/07, bansi <ma...@yahoo.com> wrote:
>>
>> Thanks David . Somehow i overlooked the setXXX method . It fixed the
>> error
>> but still it results in unnecessary database calls . Infact it results in
>> one more additional database call thereby making the total to 4. Out of
>> which only 1 is desirable the other 3 occur due to getManufacturerList()
>> I tried changing the saveState from client to server in web.xml but that
>> didnt help
>>
>> So i will appreciate if either you or Andrew could look into my snippet
>> code
>> of getManufacturerList() method in earlier posting. I am using RequestMap
>> but it results in Null pointer Exception
>>
>> Thanks for your time in advance
>> Regards
>> Bansi
>>
>>
>>
>> David Delbecq-2 wrote:
>> >
>> > You need a void setManufacturerList(List l) so saveState can restore
>> the
>> > state.
>> >
>> > bansi a écrit :
>> >> Thanks Andrew. As suggested i have placed the snippet right above
>> >> <h:form>
>> >> <f:view>
>> >>   <t:saveState id="save1" 
>> value="#{manufacturerBean.manufacturerList}"
>> >> />
>> >>   <h:form id="manufacturerForm">
>> >>
>> >> It results in following exception
>> >> javax.faces.el.PropertyNotFoundException: /manufacturerForm.xhtml
>> @23,75
>> >> value="#{manufacturerBean.manufacturerList}": Bean:
>> >> com.boeing.nmt.nams.view.bean.ManufacturerBean, property:
>> >> manufacturerList
>> >> (no write method for property!)
>> >>
>> >> I didnt understood what does it mean by "no write method for
>> property!" .
>> >> I
>> >> do have getManufacturerList in backing bean
>> >>
>> >> 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 <ma...@yahoo.com> 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#a10772815
>> 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#a10777319
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: Caching JSF Dropdown Results

Posted by Andrew Robinson <an...@gmail.com>.
List<SelectItem> manufacturerList =
(List<SelectItem>)reqMap.get(manufacturerList_KEY);
 System.out.println("manufacturerList="+manufacturerList.size());

The println statement will throw a null pointer exception as you are
calling "size()" on null the first time the function is called.

On 5/23/07, bansi <ma...@yahoo.com> wrote:
>
> Thanks David . Somehow i overlooked the setXXX method . It fixed the error
> but still it results in unnecessary database calls . Infact it results in
> one more additional database call thereby making the total to 4. Out of
> which only 1 is desirable the other 3 occur due to getManufacturerList()
> I tried changing the saveState from client to server in web.xml but that
> didnt help
>
> So i will appreciate if either you or Andrew could look into my snippet code
> of getManufacturerList() method in earlier posting. I am using RequestMap
> but it results in Null pointer Exception
>
> Thanks for your time in advance
> Regards
> Bansi
>
>
>
> David Delbecq-2 wrote:
> >
> > You need a void setManufacturerList(List l) so saveState can restore the
> > state.
> >
> > bansi a écrit :
> >> Thanks Andrew. As suggested i have placed the snippet right above
> >> <h:form>
> >> <f:view>
> >>   <t:saveState id="save1"  value="#{manufacturerBean.manufacturerList}"
> >> />
> >>   <h:form id="manufacturerForm">
> >>
> >> It results in following exception
> >> javax.faces.el.PropertyNotFoundException: /manufacturerForm.xhtml @23,75
> >> value="#{manufacturerBean.manufacturerList}": Bean:
> >> com.boeing.nmt.nams.view.bean.ManufacturerBean, property:
> >> manufacturerList
> >> (no write method for property!)
> >>
> >> I didnt understood what does it mean by "no write method for property!" .
> >> I
> >> do have getManufacturerList in backing bean
> >>
> >> 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 <ma...@yahoo.com> 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#a10772815
> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>
>

Re: Caching JSF Dropdown Results

Posted by bansi <ma...@yahoo.com>.
Thanks David . Somehow i overlooked the setXXX method . It fixed the error
but still it results in unnecessary database calls . Infact it results in
one more additional database call thereby making the total to 4. Out of
which only 1 is desirable the other 3 occur due to getManufacturerList()
I tried changing the saveState from client to server in web.xml but that
didnt help

So i will appreciate if either you or Andrew could look into my snippet code
of getManufacturerList() method in earlier posting. I am using RequestMap
but it results in Null pointer Exception

Thanks for your time in advance
Regards
Bansi



David Delbecq-2 wrote:
> 
> You need a void setManufacturerList(List l) so saveState can restore the
> state.
> 
> bansi a écrit :
>> Thanks Andrew. As suggested i have placed the snippet right above
>> <h:form>
>> <f:view>
>>   <t:saveState id="save1"  value="#{manufacturerBean.manufacturerList}"
>> /> 
>>   <h:form id="manufacturerForm">
>>
>> It results in following exception
>> javax.faces.el.PropertyNotFoundException: /manufacturerForm.xhtml @23,75
>> value="#{manufacturerBean.manufacturerList}": Bean:
>> com.boeing.nmt.nams.view.bean.ManufacturerBean, property:
>> manufacturerList
>> (no write method for property!)
>>
>> I didnt understood what does it mean by "no write method for property!" .
>> I
>> do have getManufacturerList in backing bean
>>
>> 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 <ma...@yahoo.com> 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#a10772815
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: Caching JSF Dropdown Results

Posted by David Delbecq <de...@oma.be>.
You need a void setManufacturerList(List l) so saveState can restore the
state.

bansi a écrit :
> Thanks Andrew. As suggested i have placed the snippet right above <h:form>
> <f:view>
>   <t:saveState id="save1"  value="#{manufacturerBean.manufacturerList}" /> 
>   <h:form id="manufacturerForm">
>
> It results in following exception
> javax.faces.el.PropertyNotFoundException: /manufacturerForm.xhtml @23,75
> value="#{manufacturerBean.manufacturerList}": Bean:
> com.boeing.nmt.nams.view.bean.ManufacturerBean, property: manufacturerList
> (no write method for property!)
>
> I didnt understood what does it mean by "no write method for property!" . I
> do have getManufacturerList in backing bean
>
> 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 <ma...@yahoo.com> 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.
>>>
>>>
>>>       
>>     
>
>   


Re: Caching JSF Dropdown Results

Posted by bansi <ma...@yahoo.com>.
Thanks Andrew. As suggested i have placed the snippet right above <h:form>
<f:view>
  <t:saveState id="save1"  value="#{manufacturerBean.manufacturerList}" /> 
  <h:form id="manufacturerForm">

It results in following exception
javax.faces.el.PropertyNotFoundException: /manufacturerForm.xhtml @23,75
value="#{manufacturerBean.manufacturerList}": Bean:
com.boeing.nmt.nams.view.bean.ManufacturerBean, property: manufacturerList
(no write method for property!)

I didnt understood what does it mean by "no write method for property!" . I
do have getManufacturerList in backing bean

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 <ma...@yahoo.com> 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#a10772011
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: Caching JSF Dropdown Results

Posted by bansi <ma...@yahoo.com>.
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 <ma...@yahoo.com> 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.


Re: Caching JSF Dropdown Results

Posted by Andrew Robinson <an...@gmail.com>.
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 <ma...@yahoo.com> 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.
>
>