tags:

views:

15

answers:

1

What all phases of the JSF Life cycle should get called on page refresh

+1  A: 

That entirely depends on the kind of request (POST or GET) and the available parameters. A plain vanilla GET request for example would fire the first and last phases only. A "double submit" (refreshing a form submit) would by default go through all phases, but depending on the presence of the immediate="true" in UIInput and/or UICommand components, some phases might be skipped.

You can create yourself a simple PhaseListener and play around with it to learn which phases are executed and which not.

package mypackage;

import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;

public class LifeCycleListener implements PhaseListener {

    public PhaseId getPhaseId() {
        return PhaseId.ANY_PHASE;
    }

    public void beforePhase(PhaseEvent event) {
        System.out.println("START PHASE " + event.getPhaseId());
    }

    public void afterPhase(PhaseEvent event) {
        System.out.println("END PHASE " + event.getPhaseId());
    }

}

Register it as follows in faces-config.xml to get it to run:

<lifecycle>
    <phase-listener>mypackage.LifeCycleListener</phase-listener>
</lifecycle>

See also:

BalusC