I have an Action in request scope. The return value of one of its methods is passed around to a custom facelet tag. This tag then extracts several attributes of the returned object and displays them. The problem is the EL expression which has the method call on the Action is called for every evaluation of the attribute of the returned object. I will put the relevent pieces of code here.
some.xhtml
<ui:include src="someOther.xhtml">
<ui:param name="profileUri" value="#{param['relateToProfile']}"/>
<ui:param name="qualifier" value="#{param['qualifier']}"/>
<ui:param name="cellStyleClass" value="#{param['cellStyle']}"/>
</ui:include>
someOther.xhtml (approach 1) Note that ProfileAction is in @RequestScoped
<tenui:entityCard profileEntity="#{profileAction.getProfileMetadata(profileUri)}"
qualifier="#{qualifier}"
cellStyleClass="#{cellStyleClass}"/>
enityCard.xhtml(facelet custom tag)
<ui:fragment rendered="#{profileEntity.featured}">...
<tenui:gridCell id="#{profileEntity.profileId}#{qualifier}" ...
<tenui:metaunit ..content="#{profileEntity.getMeta('memberName')}"
href="/#{profileEntity.profileDisplayUri}"
hrefStyleClass="a-styled grid-cell-name"/>
.....
...several other EL expressions including #{profileEntity.xxx}
The problem is #{profileAction.getProfileMetadata(profileUri)} is being called for every attribute evaluation in entityCard.xhtml Then, I thought I would save the return value of method call in a c:set var(approach 2 as noted below) but it doesn't help.
someOther.xhtml (approach 2)
<c:set var="profileMetadata"
value="#{profileAction.getProfileMetadata(profileUri)}"/>
<tenui:entityCard profileEntity="#{profielMetadata}"
qualifier="#{qualifier}"
cellStyleClass="#{cellStyleClass}"/>
The action method calls a Stored proc which is quite expensive and the returned object has over 20 attributes that get evaluated in ELs in entityCard.xhtml.
I also tried another approach with resolving teh value at ui:param itself by calling the action method directly, but of no avail at all. The problem remained.
Can someone point to what could I be doing wrong? Or, how I could avoid the multiple calls to profileAction.getProfileMetadata call?