Reputation: 12447
My code here iterates the columns for each row and the rendered
attribute is calculated every iteration, overcalling testRule
.
<p:dataTable ...>
<p:column ...>
...
</p:column>
<p:column rendered="#{managedBean.testRule('rules.canDoActions')}">
<!-- Action buttons -->
<h:commandButton ...>
<h:commandButton ...>
</p:column>
</p:dataTable>
To get better performance, I was wondering to set the result into a variable, but I don't know how... It would become something like this:
<?:??? var="canDoActions" value="#{managedBean.testRule('rules.canDoActions')}">
<p:dataTable ...>
<p:column ...>
...
</p:column>
<p:column rendered="#{canDoActions}">
<!-- Action buttons -->
<h:commandButton ...>
<h:commandButton ...>
</p:column>
</p:dataTable>
Also, I'm not allowed to use Core Tag Library, wich means that <c:set ../>
is out of question.
In that scope, how could I set a variable? Or, if not possible, what do you suggest to solve the performance?
Upvotes: 4
Views: 10874
Reputation: 240898
I'm not allowed to use Core Tag Library, wich means that
<c:set ../>
is out of question
Then you can have it stored on Bean itself and check if it is null calculateRules and set value or simply return.
For Example:
HashMap<String, Boolean> map;
public boolean testRule(String stringInput) {
Boolean result = map.get(stringInput);
if (result == null) {
//calculate and set in map
}
return result;
}
Upvotes: 6