0

How can I avoid calling a function on my bean more than once if I have several HTML elements that call this function in their rendered attribute?

<h:outputText value="1" rendered="#{myBean.myFunc() eq 70}"/> 
<h:outputText value="2" rendered="#{myBean.myFunc() eq 42}"/>

Here, the second outputText will unnecessarily call myFunc() again. Is it possible to avoid this behavior?

dasLort
  • 1,264
  • 1
  • 13
  • 28
  • You could store the result of myFunc() in a variable and use that instead. But then you need to call myFunc() yourself somewhere. Still that is what i would do. But you could also use some sort of caching like ehcache, but that might be overkill. – Mario B Nov 19 '14 at 10:33
  • possible duplicate of [Defining and reusing variable in JSF page](http://stackoverflow.com/questions/6434866/defining-and-reusing-variable-in-jsf-page) – futureelite7 Nov 19 '14 at 10:36

1 Answers1

0

This answer by BalusC provides a nice way to set and reuse variables in JSF.

Community
  • 1
  • 1
dubes
  • 5,324
  • 3
  • 34
  • 47