title: JSF preRenderView called too many times
body: <p>A page/bean of mine has its <code>preRenderView</code> event fired twice on the first page load then <code>2 + n</code> times for each postback, where <code>n</code> is the number of postbacks (including the current one) that have occurred.</p>
  
  <p>After reading a few other posts here, I moved <code>&lt;f:event type="preRenderView" listener="myBean.preRenderView"/&gt;</code> outside of <code>&lt;f:metadata/&gt;</code> and that reduced the number of <code>preRenderView</code> calls by one. That is, it is called once on the full page load and <code>1 + n</code> times for each postback. I even tried to move the <code>&lt;f:event/&gt;</code> tag outside of <code>&lt;f:view/&gt;</code>, but it had no effect.</p>
  
  <p>I'm not sure if this is relevant: The page uses a template:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:fb="http://www.facebook.com/2008/fbml"&gt;
      &lt;f:view contentType="text/html"&gt;
          &lt;ui:insert name="metadata"/&gt;
          &lt;h:head&gt;
              &lt;!-- Some stuff here --&gt;
              &lt;ui:insert name="content"/&gt;
              &lt;!-- More stuff here --&gt;
          &lt;/h:head&gt;
          &lt;h:body&gt;
          &lt;/h:body&gt;
      &lt;/f:view&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And the relevant bits of the page:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:ui="http://java.sun.com/jsf/facelets"&gt;
      &lt;h:head&gt;
          &lt;title&gt;&lt;/title&gt;
      &lt;/h:head&gt;
      &lt;h:body&gt;
          &lt;ui:composition template="/WEB-INF/templates/myLayout.xhtml"&gt;
              &lt;ui:define name="windowTitle"&gt;My Page&lt;/ui:define&gt;
              &lt;ui:define name="metadata"&gt;
                  &lt;f:event type="preRenderView" listener="#{myBean.preRenderView}"/&gt;
              &lt;/ui:define&gt;
              &lt;ui:define name="content"&gt;
                  &lt;!-- Some content here --&gt;
                  &lt;h:panelGroup id="reRenderable" layout="block"&gt;
                      &lt;!-- More content here --&gt;
                      &lt;h:form prependId="false"&gt;
                          &lt;h:outputLabel for="mySelector" value="Item:"/&gt;
                          &lt;h:selectOneMenu id="mySelector"
                                           value="#{myBean.item}"
                                           converter="#{myConverter}"
                                           validator="#{itemActiveValidator.validate}"&gt;
                              &lt;f:selectItems value="#{myBean.myItems}"/&gt;
                              &lt;f:ajax render=":reRenderable"/&gt;
                          &lt;/h:selectOneMenu&gt;
                      &lt;/h:form&gt;
                      &lt;!-- More content here --&gt;
                  &lt;/h:panelGroup&gt;
                  &lt;!-- More content here --&gt;
              &lt;/ui:define&gt;
          &lt;/ui:composition&gt;
      &lt;/h:body&gt;
  &lt;/html&gt;
  </code></pre>