Well, that should be interesting, I think. I want to minimize the number of calls for my Seam component inside an iteration. I am using Seam 2.2.1.CR1, Richfaces 3.3.3.Final, JSF 1.2 and Facelets.
Please see the following Facelet snippet:
<rich:datatable value="#{myBean.products}" var="prod"> <rich:column rowspan="#{rowspan.calcHomePageProductRowspan(prod)}"> #{prod.name} </rich:column> <rich:column rowspan="#{rowspan.calcHomePageProductRowspan(prod)}"> #{prod.number} </rich:column> ... <rich:column rowspan="#{rowspan.calcHomePageProductRowspan(prod)}"> #{prod.somethingElse1} </rich:column> <rich:column rowspan="#{rowspan.calcHomePageProductRowspan(prod)}"> #{prod.somethingElse2} </rich:column> ... <rich:column rowspan="#{rowspan.calcHomePageProductRowspan(prod)}"> #{prod.somethingElse3} </rich:column> </rich:datatable>
In the code above, I compute the attribute (here is rowspan, but it doesn't really matter, it can be any attribute or value at all, so please don't focus on that), evaluating the EL expression. As you can see, the method that evaluates the value takes the current prod as an argument.
I did an internal optimization in the rowspan Seam component, and it saves all the calculated values ββfor the products in the HashMap. So, when the EL expression is evaluated in the second rich:column , rowspan first looks up the already calculated value in the HashMap and returns it instead of re-evaluating it again and again.
Although this is better than recalculating over and over, I still have to make a call for the Seam component. Is there a way to somehow call the Seam component only once and somehow save the calculated value for the current iteration?
Similarly, Java will define a variable inside the loop at each iteration and reuse it during the iteration.
Note. I have already done other Seam-oriented optimizations, such as @BypassInterceptors, the Seam component is in the EVENT area, so there is no hierarchical search, etc.