/**
 * 
 */
package org.ajax4jsf.portlet.lifecycle;

import java.io.IOException;

import javax.faces.FacesException;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseId;
import javax.faces.lifecycle.Lifecycle;

/**
 * @author asmirnov
 *
 */
public class RenderResponsePhase extends LifecyclePhase {

	/**
	 * @param lifecycle
	 */
	public RenderResponsePhase(Lifecycle lifecycle) {
		super(lifecycle);
	}

	/* (non-Javadoc)
	 * @see org.ajax4jsf.portlet.lifecycle.LifecyclePhase#executeNextPhase(javax.faces.context.FacesContext, javax.faces.event.PhaseListener[])
	 */
	protected void executeNextPhase(FacesContext context) {
		// do nothing.

	}

	/* (non-Javadoc)
	 * @see org.ajax4jsf.portlet.lifecycle.LifecyclePhase#executePhase(javax.faces.context.FacesContext)
	 */
	public void executePhase(FacesContext context) {
        try {
            context.getApplication().getViewHandler().
                    renderView(context, context.getViewRoot());
        } catch (FacesException e) {
            throw e;
        } catch (IOException e) {
            throw new FacesException(e);
        }
	}

	/* (non-Javadoc)
	 * @see org.ajax4jsf.portlet.lifecycle.LifecyclePhase#getPhaseId()
	 */
	protected PhaseId getPhaseId() {
		// TODO Auto-generated method stub
		return PhaseId.RENDER_RESPONSE;
	}

}
