Friday, May 24, 2013

Alternative solution on PreRenderView

Usually when I want to determine whether the page is first loaded, I will put the following code in Facelet template.


Unfortunately that solution does not work under JSF 2.0 and below. The alternative is to add beforePhase attribute name right inside the <f:view> tag like this:

On the action class, add following code to perform the necessary task need to be complete before a page is render:
    public void doPreRenderView(PhaseEvent event) {
      if (event.getPhaseId() == PhaseId.RENDER_RESPONSE) {
        // do your stuff

No comments: