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/08 17:52:22 UTC

JSF Dropdown Perfomance Issues

I have a h:selectOneMenu dropdown  which  performs CRUD operation.
The dropdown list has a  value "New"  which allows the users to enter new
values into  other form fields thereby performing Create/Insert operation
When users pick other values from the dropdown list it dynamically populates
other fields in the form thereby facilitating Update/Delete operation. The
problem is whenever i pick a different value from the dropdown list the
database call happens twice.

Here is the dropdown
Code:


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




Here is the sequence of method calls whenever i pick a value from the
dropdown list
- First time the method in f:selectItems gets called which results in a
database call
<f:selectItems value="#{manufacturerBean.manufacturerList}" />
- Second time 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}" />

Here are my concerns
- Just picking a value from the dropdown shouldn't result in a call to
database especially when there are no changes made to database

- I expect the calls to database happens ONLY in case of users click
Save/Update/Delete buttons i.e. dropdown dynamically refreshes with database
values

Here are the snippets from log file which substantiates that whenever i pick
a value from dropdown
database call occurs twice
Code:

********** FIRST METHOD CALL ***************************
2007-05-07 16:46:46,002 INFO
[com.boeing.nmt.nams.view.bean.ManufacturerBean] - < *** In
getManufacturerList Backing Bean*** >
2007-05-07 16:46:46,002 INFO
[com.boeing.nmt.nams.service.impl.ManufacturerManagerImpl] - < *** In
getManufacturerList Spring*** >
Hibernate: select namsmanufa0_.ID as ID60_, namsmanufa0_.CHANGE_USER as
CHANGE2_60_, namsmanufa0_.NA
ME as NAME60_, namsmanufa0_.DESCRIPTION as DESCRIPT4_60_,
namsmanufa0_.SOURCE as SOURCE60_, namsmanu
fa0_.STATUS as STATUS60_, namsmanufa0_.CHANGE_DATE as CHANGE7_60_ from
NAMS_MANUFACTURER namsmanufa0
_

********** SECOND METHOD CALL ***************************
2007-05-07 16:46:46,237 INFO
[com.boeing.nmt.nams.view.bean.ManufacturerBean] - < *** In
loadManufacturerDetails method *** >
Hibernate: select namsmanufa0_.ID as ID60_0_, namsmanufa0_.CHANGE_USER as
CHANGE2_60_0_, namsmanufa0
_.NAME as NAME60_0_, namsmanufa0_.DESCRIPTION as DESCRIPT4_60_0_,
namsmanufa0_.SOURCE as SOURCE60_0_
, namsmanufa0_.STATUS as STATUS60_0_, namsmanufa0_.CHANGE_DATE as
CHANGE7_60_0_ from NAMS_MANUFACTUR
ER namsmanufa0_ where namsmanufa0_.ID=?

********** THIRD METHOD CALL ***************************
2007-05-07 16:46:46,565 INFO
[com.boeing.nmt.nams.view.bean.ManufacturerBean] - < *** In
getManufacturerList Backing Bean*** >
2007-05-07 16:46:46,565 INFO
[com.boeing.nmt.nams.service.impl.ManufacturerManagerImpl] - < *** In
getManufacturerList Spring*** >
Hibernate: select namsmanufa0_.ID as ID60_, namsmanufa0_.CHANGE_USER as
CHANGE2_60_, namsmanufa0_.NA
ME as NAME60_, namsmanufa0_.DESCRIPTION as DESCRIPT4_60_,
namsmanufa0_.SOURCE as SOURCE60_, namsmanu
fa0_.STATUS as STATUS60_, namsmanufa0_.CHANGE_DATE as CHANGE7_60_ from
NAMS_MANUFACTURER namsmanufa0
_



I do have Managed Bean in Session scope

Regards
Bansi 
-- 
View this message in context: http://www.nabble.com/JSF-Dropdown-Perfomance-Issues-tf3710469.html#a10378469
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: JSF Dropdown Perfomance Issues

Posted by David Delbecq <de...@oma.be>.
En l'instant précis du 08/05/07 17:52, bansi s'exprimait en ces termes:
>
> <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> 
>
>
> Here are my concerns
> - Just picking a value from the dropdown shouldn't result in a call to
> database especially when there are no changes made to database
>   
When you pickup a data an submit form (that's what a4j does), JSF ensure
the value user selected is in the list of available values. This is part
of validation process. To do this, it iterate over child select items,
resulting in a call to get f:selectItems entries, resulting in
evaluation of #{manufacturerBean.manufacturerList}. If you want to
prevent useless database calls, you must do it in manufacturerList.
f:selectItems is stateless and won't keep the list in cache.

Note: you might want to consider the Hibernate second level cache &
query caching to prevent too many database queries.