too many Seam component executions from JSF
gonorrhea Jun 19, 2009 7:06 PMThis is a general problem with JSF but I am trying to use Seam factory component pattern to solve it.
xhtml:
<a4j:outputPanel ajaxRendered="true"> <!-- <a4j:outputPanel id="undefinedItemNumbersOutputPanel"> --> <h:panelGrid columns="2" rendered="#{recoveredEquipmentManagement.totalUndefined > 0 and recoveredEquipmentManagementList.getRowCount() > 0}"> <s:graphicImage value="/img/warning_red_lg.jpg"/> <h:outputText value="There are #{recoveredEquipmentManagement.totalUndefined} undefined item number(s)."/> </h:panelGrid> </a4j:outputPanel>
SFSB:
//ScopeType.EVENT does not make totalUndefined display/refresh in time when we submit a change in modal edit screen... //@Factory(value="totalUndefined", scope=ScopeType.EVENT) //NOTE: see this thread regarding order of events and @Factory pattern: http://www.seamframework.org/Community/FactoryAnnotationAndOrderOfEventsInSFSB //NOTE: this method is being executed multiple times in one HTTP req/resp. cycle!!! public Long getTotalUndefined(){ Long totalUndefined = (Long)entityManager.createQuery("select count(*) "+ " from RecoveredEquipmentManagement rem "+ " where rem.recoveryType = ( SELECT lv.listValueId "+ " FROM ListValue lv, List l "+ " WHERE l.listId = lv.list.listId "+ " and l.listName = :recoveryType"+ " and lv.listValue = :undefined)") .setParameter("recoveryType", RECOVERY_TYPE) .setParameter("undefined", UNDEFINED) .getSingleResult(); return totalUndefined; }
The getTotalUndefined() method is being executed approx. 8 - 12 times depending on what other a4j: activities (form submissions) are occurring.
I want the getTotalUndefined() method to be executed after the first form/search submission (after Hibernate Criteria API query executes and returns resultset to populate the dataTable). I then want it to re-exec after the user edits one of the values in one of the rows of the dataTable in a modalPanel embedded h:form.
The problem is that the only way the totalUndefined number is updated and reRendered properly is when I do not use the @Factory(value="totalUndefined", scope=ScopeType.EVENT). The idea behind using the @Factory(value="totalUndefined", scope=ScopeType.EVENT) is to prevent the method from being executed too many times during the JSF life cycle and various a4j:/rich: (I'm using a rich:suggestionBox in one of the form search fields) activities.
Anybody know best way to solve this? It's a very annoying characteristic
of JSF... I wonder if they addressed this problem at all in JSF 2.0...
I'm not sure if @Factory(value="totalUndefined", scope=ScopeType.PAGE) would work because the method would only be executed once per xhtml main page (unless manually set to null) and that is not appropriate either.
I can't even pass a param to the method, that's too complicated and won't work with JSF binding events...