Ok, I not only survived a horrible breakdown. I need to be a bit patient and hopefully I’ll be fully restored. Time to talk about life cycle. Lifecycle of JSF. Not a full-fledged article yet, but a tutorial to find out by yourself.

Like before, I use NetBeans for explanation. Create a new   web application an. Tag “Enable Context and Dependency Injection”. Choose JSF as framework with an extension of “*.xhtml” for URL pattern. This has been a very short explanation. For details and sreenshots refer to Part II of my JSF tutorial.

Complete the generated index.xhtlm:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml"
               <f:phaseListener type="demo.LifeCycleListener"/>

               <title>Facelet Title</title>
               Hello from Facelets

               <h:form id="form">
                               <h:outputLabel for="name" value="Name:"/>
                               <h:inputText id="name" value="#{backingBean.name}"/>
                               <h:outputLabel for="age" value="Age:"/>
                               <h:inputText id="age" value="#{backingBean.age}"/>
                               <h:commandButton value="Ok"/>

Create a package and name it “demo”.

Create “JSF managed bean” and provide a name of “BackingBean”. Indeed, because you’ve enabled CDI, it will be a named bean. Or just create java class and extend it’s code to become a named bean.

package demo;

import javax.enterprise.context.RequestScoped;
import javax.inject.Named;

public class BackingBean {

       private String _name;
       private int _age;

       public String getName() {
               return _name;

       public void setName(String name) {
               this._name = name;

       public int getAge() {
               return _age;

       public void setAge(int age) {
               this._age = age;

Add a second bean with name of “LifeCycleListener”.

package demo;

import javax.enterprise.context.Dependent;
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;
import javax.inject.Named;

public class LifeCycleListener implements PhaseListener {

       public void beforePhase(PhaseEvent event) {
               System.out.println("Before phase: " + event.getPhaseId());

       public void afterPhase(PhaseEvent event) {
               System.out.println("After phase: " + event.getPhaseId());

       public PhaseId getPhaseId() {
               return PhaseId.ANY_PHASE;


Start the project and wath the output of the NetBeans output window, tab GlassFish Server. Provide a name and age and click onto [OK]. Use some letters instead of numeric for field age and click [Ok] again. Did you recognize the difference?

I’ll provide detailed explanation when I’ll get time again.


To web development content.