title: Why JSF calls getters multiple times
body: <p>Let's say I specify an outputText component like this:</p>
  
  <pre><code>&lt;h:outputText value="#{ManagedBean.someProperty}"/&gt;
  </code></pre>
  
  <p>If I print a log message when the getter for <code>someProperty</code> is called and load the page, it is trivial to notice that the getter is being called more than once per request (twice or three times is what happened in my case):</p>
  
  <pre><code>DEBUG 2010-01-18 23:31:40,104 (ManagedBean.java:13) - Getting some property
  DEBUG 2010-01-18 23:31:40,104 (ManagedBean.java:13) - Getting some property
  </code></pre>
  
  <p>If the value of <code>someProperty</code> is expensive to calculate, this can potentially be a problem.</p>
  
  <p>I googled a bit and figured this is a known issue. One workaround was to include a check and see if it had already been calculated:</p>
  
  <pre><code>private String someProperty;
  
  public String getSomeProperty() {
      if (this.someProperty == null) {
          this.someProperty = this.calculatePropertyValue();
      }
      return this.someProperty;
  }
  </code></pre>
  
  <p>The main problem with this is that you get loads of boilerplate code, not to mention private variables that you might not need.</p>
  
  <p>What are the alternatives to this approach? Is there a  way to achieve this without so much unnecessary code? Is there a way to stop JSF from behaving in this way?</p>
  
  <p>Thanks for your input!</p>