Java EE 8 By Example
  • Introduction
  • Overview
    • Example Codes
  • JSF 2.3
    • Activating CDI in JSF 2.3
    • Run applications in JSF 2.2 compatible mode
    • CDI alignment
    • CDI compatible @ManagedProperty
    • Inject support in Converter, Validator and Behavor
    • Websocket support
    • UIData improvements
    • Class level bean validation with f:valdiateWholeBean
    • Java 8 DateTime support
    • PostRenderViewEvent: publising events after view is rendered
    • Search expression framework
  • CDI 2.0
    • Java SE support
    • Event Priority
    • Async Events
    • Register Beans dynamicially
    • Configurators and Intercept Producers
  • JPA 2.2
    • Java 8 Datetime support
    • Return Stream based result from Query
    • More CDI Alignments
  • JSON-B 1.0
  • JSON-P 1.1
  • Bean Validation 2.0
  • JAXRS 2.1
    • Async improvements
    • Server Sent Event
    • Reactive Client
  • Java EE Security API 1.0
    • HttpAuthenticationMechanism
    • IdentityStore
    • SecurityContext
  • Servlet 4.0
    • Server Push
    • Runtime Discovery of Servlet Mappings
    • Http Trailer
  • MVC 1.0
    • Getting started with MVC
    • Handling form submission
    • Exception handling and form validation
    • Processing PUT and DELETE methods
    • Page navigation
    • MVC and CDI
    • Security
    • Bean parameter conversion
    • View engine
Powered by GitBook
On this page

Was this helpful?

  1. JSF 2.3

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}.

<f:metadata>
    <f:event type="preRenderView" listener="#{postRenderViewBean.init}" />
    <f:viewAction action="#{postRenderViewBean.execute}" />
    <f:event type="postRenderView" listener="#{postRenderViewBean.initialized}"/>
</f:metadata>

You will see the info in the IDE console.

Info:   before phase:RESTORE_VIEW 1
Info:   after phase:RESTORE_VIEW 1
Info:   invoking custom ExceptionHandlder...
Info:   before phase:APPLY_REQUEST_VALUES 2
Info:   after phase:APPLY_REQUEST_VALUES 2
Info:   invoking custom ExceptionHandlder...
Info:   before phase:PROCESS_VALIDATIONS 3
Info:   after phase:PROCESS_VALIDATIONS 3
Info:   invoking custom ExceptionHandlder...
Info:   before phase:UPDATE_MODEL_VALUES 4
Info:   after phase:UPDATE_MODEL_VALUES 4
Info:   invoking custom ExceptionHandlder...
Info:   before phase:INVOKE_APPLICATION 5
Info:   execute viewAction
Info:   after phase:INVOKE_APPLICATION 5
Info:   invoking custom ExceptionHandlder...
Info:   before phase:RENDER_RESPONSE 6
Info:   fire PreRenderViewEvent:javax.faces.event.PreRenderViewEvent[source=javax.faces.component.UIViewRoot@248724dd]
Info:   fire PostRenderViewEvent:javax.faces.event.PostRenderViewEvent[source=javax.faces.component.UIViewRoot@248724dd]
Info:   after phase:RENDER_RESPONSE 6
Info:   invoking custom ExceptionHandlder...

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

PreviousJava 8 DateTime supportNextSearch expression framework

Last updated 4 years ago

Was this helpful?

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

Run this application on Glassfish v5, open browser and navigate to ;

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

Java EE 7 sample
http://localhost:8080/jsf-postrenderview-event/postRenderView.faces
source codes