📄 lifecycleimpl.java
字号:
/* * Copyright 2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.myfaces.lifecycle;import org.apache.myfaces.util.DebugUtils;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import javax.faces.FacesException;import javax.faces.application.Application;import javax.faces.application.ViewHandler;import javax.faces.component.UIComponent;import javax.faces.component.UIInput;import javax.faces.component.UIViewRoot;import javax.faces.context.ExternalContext;import javax.faces.context.FacesContext;import javax.faces.el.ValueBinding;import javax.faces.event.PhaseEvent;import javax.faces.event.PhaseId;import javax.faces.event.PhaseListener;import javax.faces.lifecycle.Lifecycle;import java.io.IOException;import java.util.ArrayList;import java.util.Arrays;import java.util.Iterator;import java.util.List;import javax.portlet.PortletRequest;import org.apache.myfaces.portlet.MyFacesGenericPortlet;import org.apache.myfaces.portlet.PortletUtil;/** * Implements the lifecycle as described in Spec. 1.0 PFD Chapter 2 * @author Manfred Geiler (latest modification by $Author: matzew $) * @version $Revision: 1.44 $ $Date: 2005/02/10 20:24:17 $ * $Log: LifecycleImpl.java,v $ * Revision 1.44 2005/02/10 20:24:17 matzew * closed MYFACES-101 in Jira; Thanks to Stan Silvert (JBoss Group) * * Revision 1.43 2005/01/27 02:38:43 svieujot * Remove portlet-api dependency while keeping portlet support. * * Revision 1.42 2005/01/26 17:03:11 matzew * MYFACES-86. portlet support provided by Stan Silver (JBoss Group) * * Revision 1.41 2004/10/13 11:51:00 matze * renamed packages to org.apache * * Revision 1.40 2004/08/25 13:54:02 manolito * Log cvs keyword * */public class LifecycleImpl extends Lifecycle{ private static final Log log = LogFactory.getLog(LifecycleImpl.class); private List _phaseListenerList = new ArrayList(); private PhaseListener[] _phaseListenerArray = null; public LifecycleImpl() { // hide from public access } public void execute(FacesContext facesContext) throws FacesException { if (restoreView(facesContext)) { return; } if (applyRequestValues(facesContext)) { return; } if (processValidations(facesContext)) { return; } if (updateModelValues(facesContext)) { return; } if (invokeApplication(facesContext)) { return; } } // Phases /** * Restore View (JSF.2.2.1) * @return true, if immediate rendering should occur */ private boolean restoreView(FacesContext facesContext) throws FacesException { if (log.isTraceEnabled()) log.trace("entering restoreView in " + LifecycleImpl.class.getName()); informPhaseListenersBefore(facesContext, PhaseId.RESTORE_VIEW); // Derive view identifier String viewId = deriveViewId(facesContext); Application application = facesContext.getApplication(); ViewHandler viewHandler = application.getViewHandler(); boolean viewCreated = false; UIViewRoot viewRoot = viewHandler.restoreView(facesContext, viewId); if (viewRoot == null) { viewRoot = viewHandler.createView(facesContext, viewId); facesContext.renderResponse(); viewCreated = true; } facesContext.setViewRoot(viewRoot); if (log.isTraceEnabled()) { //Note: DebugUtils Logger must also be in trace level DebugUtils.traceView(viewCreated ? "Newly created view" : "Restored view"); } if (facesContext.getExternalContext().getRequestParameterMap().isEmpty()) { //no POST or query parameters --> set render response flag facesContext.renderResponse(); } recursivelyHandleComponentReferencesAndSetValid(facesContext, viewRoot); informPhaseListenersAfter(facesContext, PhaseId.RESTORE_VIEW); if (facesContext.getRenderResponse()) { if (log.isDebugEnabled()) log.debug("exiting restoreView in " + LifecycleImpl.class.getName() + " (--> render response)"); return true; } if (log.isTraceEnabled()) log.trace("exiting restoreView in " + LifecycleImpl.class.getName()); return false; } /** * Apply Request Values (JSF.2.2.2) * @return true, if response is complete */ private boolean applyRequestValues(FacesContext facesContext) throws FacesException { if (log.isTraceEnabled()) log.trace("entering applyRequestValues in " + LifecycleImpl.class.getName()); informPhaseListenersBefore(facesContext, PhaseId.APPLY_REQUEST_VALUES); facesContext.getViewRoot().processDecodes(facesContext); informPhaseListenersAfter(facesContext, PhaseId.APPLY_REQUEST_VALUES); if (facesContext.getResponseComplete()) { if (log.isDebugEnabled()) log.debug("exiting applyRequestValues in " + LifecycleImpl.class.getName() + " (response complete)"); return true; } if (facesContext.getRenderResponse()) { if (log.isDebugEnabled()) log.debug("exiting applyRequestValues in " + LifecycleImpl.class.getName() + " (--> render response)"); return true; } if (log.isTraceEnabled()) log.trace("exiting applyRequestValues in " + LifecycleImpl.class.getName()); return false; } /** * Process Validations (JSF.2.2.3) * @return true, if response is complete */ private boolean processValidations(FacesContext facesContext) throws FacesException { if (log.isTraceEnabled()) log.trace("entering processValidations in " + LifecycleImpl.class.getName()); informPhaseListenersBefore(facesContext, PhaseId.PROCESS_VALIDATIONS); facesContext.getViewRoot().processValidators(facesContext); informPhaseListenersAfter(facesContext, PhaseId.PROCESS_VALIDATIONS); if (facesContext.getResponseComplete()) { if (log.isDebugEnabled()) log.debug("exiting processValidations in " + LifecycleImpl.class.getName() + " (response complete)"); return true; } if (facesContext.getRenderResponse()) { if (log.isDebugEnabled()) log.debug("exiting processValidations in " + LifecycleImpl.class.getName() + " (--> render response)"); return true; } if (log.isTraceEnabled()) log.trace("exiting processValidations in " + LifecycleImpl.class.getName()); return false; } /**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -