Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are different ways to achieve this. First of all, you must define what you mean with "when the Facelets page loads". I assume you mean before the page is rendered.</p> <p><strong>PreRenderViewEvent</strong></p> <p>With JSF 2.x the simplest way to do this is a system event listener for <code>PreRenderViewEvent</code>. For this you first need a <code>f:event</code> tag in your page like this:</p> <pre><code>&lt;f:event type="javax.faces.event.PreRenderViewEvent" listener="#{bean.preRenderView}"/&gt; </code></pre> <p>Listeners for <code>PreRenderViewEvent</code> must be registered on the view root (<code>f:view</code>). So <code>f:event</code> must be a direct child of <code>f:view</code> or somewhere top level if you do not use <code>f:view</code>. With templating <code>f:event</code> must be put inside a <code>ui:define</code> that guarantees the same.</p> <p>The listener method referenced in the <code>listener</code> attribute is called before the view is rendered. The method might look like this:</p> <pre><code>public void preRenderView(ComponentSystemEvent ev) { //Do something } </code></pre> <p><strong>@PreRenderView</strong></p> <p>If you use CDI with MyFaces CODI, you can simply annotate a managed bean method with <code>@PreRenderView</code> and it will be called before the page is rendered.</p> <p><strong>View actions</strong></p> <p>With JSF 2.2 (not yet final) you can use view actions to call methods at different phases of the lifecycle. See my <a href="http://jsflive.wordpress.com/2013/03/22/jsf22-view-actions/" rel="nofollow">JSFlive post on JSF 2.2 view actions</a> for details.</p> <p>You can find examples for <code>PreRenderViewEvent</code> and view actions in my <a href="https://github.com/jsflive/jsf-get-examples" rel="nofollow">GitHub repository</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload