PostRenderViewEvent: publising events after view is rendered

JSF 2.3 added a new ComponentSystemEvent, the so-called PostRenderViewEvent, it will be fired after the view is rendered in the RENDER_RESPONSE phase.

Create a sample to taste it.

Firstly create a backing bean.

@Model
public class PostRenderViewBean {

    @Inject
    Logger LOG;

    public void init(PreRenderViewEvent e) {
        LOG.log(Level.INFO, "fire PreRenderViewEvent:" + e);
    }

    public void execute() {
        LOG.log(Level.INFO, "execute viewAction");
    }

    public void initialized(PostRenderViewEvent e) {
        LOG.log(Level.INFO, "fire PostRenderViewEvent:" + e);
    }
}

In the facelets template, use f:event to declare events, and set type to postRenderView and listener to #{postRenderViewBean.initialized}.

viewAction was added in Java EE 7, check my Java EE 7 sample for details.

Run this application on Glassfish v5, open browser and navigate to http://localhost:8080/jsf-postrenderview-event/postRenderView.faces;

You will see the info in the IDE console.

The viewAction is executed in INVOKE_APPLICATION phase, and PreRenderViewEvent and PostRenderViewEvent are fired in RENDER_RESPONSE phase.

Grab the source codes from my GitHub account, and have a try.

Last updated

Was this helpful?