/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

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

/**
 *
 * @author x
 */
public class ZeichPhasen implements PhaseListener {

  private void zeichAnalyse() {
    FacesContext fc = FacesContext.getCurrentInstance();
    Analyse a = fc.getApplication().evaluateExpressionGet(fc, "#{analyse}", Analyse.class);
    System.out.println("A: " + a.getEin() + " :: " + a.getZahl());
  }

  @Override
  public void beforePhase(PhaseEvent e) {
    if (e.getPhaseId() == PhaseId.RESTORE_VIEW) {
      System.out.println("===geht los");
    }
    System.out.println("before: " + e.getPhaseId());
    zeichAnalyse();
  }

  @Override
  public void afterPhase(PhaseEvent e) {
    System.out.println("after: " + e.getPhaseId());
    zeichAnalyse();
    if (e.getPhaseId() == PhaseId.RENDER_RESPONSE) {
      System.out.println("===is Schicht");
    }
  }

  @Override
  public PhaseId getPhaseId() {
    //System.out.println("getPhaseId()");
    return PhaseId.ANY_PHASE;
  }
}
