📄 facescontroller.java
字号:
/* * Copyright 2002-2004 the original author or authors. * * 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 de.mindmatters.faces.spring.context.servlet;import java.util.Map;import javax.faces.FactoryFinder;import javax.faces.context.FacesContext;import javax.faces.lifecycle.Lifecycle;import javax.faces.lifecycle.LifecycleFactory;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.springframework.beans.factory.InitializingBean;import org.springframework.util.Assert;import org.springframework.web.servlet.ModelAndView;import org.springframework.web.servlet.View;import org.springframework.web.servlet.mvc.AbstractController;/** * <strong>FacesController</strong> is a Controller that manages the request * processing lifecycle for web applications that are utilizing JavaServer Faces * to construct the user interface. * * <p> * This Controller is an appropriate alternative for the <strong>FacesServlet</strong>. * </p> * * <p> * <h4>Exposed configuration properties:</h4> * <table class="javaDoc"> * <tr> * <th>name</th> * <th>default</th> * <th>description</th> * </tr> * <tr> * <td>lifecycleId</td> * <td>{@link LifecycleFactory#DEFAULT_LIFECYCLE}</td> * <td>the identifier of the {@link Lifecycle} this Controller is delegating * the request processing</td> * </tr> * </table> * * @author Andreas Kuhrwahl * * @see javax.faces.webapp.FacesServlet * */public class FacesController extends AbstractController implements InitializingBean { /** * {@link View} implementation. Delegates to * {@link Lifecycle#render(FacesContext)} of the proper lifecycle the * nesting Controller runs in. * * @author Andreas Kuhrwahl * */ private class DefaultFacesView implements View { /** * {@inheritDoc} */ public String getContentType() { return null; } /** * {@inheritDoc} */ public void render(final Map model, final HttpServletRequest request, final HttpServletResponse response) throws Exception { FacesController.this.lifecycle.render(FacesContext .getCurrentInstance()); } } /** The JSF lifecycle for execution and rendering. */ private Lifecycle lifecycle; /** The id for the currently used lifecycle. */ private String lifecycleId = LifecycleFactory.DEFAULT_LIFECYCLE; /** * Initializes the faces lifecycle this controller runs in. * * @throws Exception * in cases of errors */ public final void afterPropertiesSet() throws Exception { LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder .getFactory(FactoryFinder.LIFECYCLE_FACTORY); this.lifecycle = lifecycleFactory.getLifecycle(this.lifecycleId); initFacesController(); } /** * This method allows the bean instance to perform initialization only * possible when all bean properties have been set and to throw an exception * in the event of misconfiguration. * * @throws Exception * in the event of misconfiguration (such as failure to set an * essential property) or if initialization fails. */ protected void initFacesController() throws Exception { } /** * Sets the lifecycle id for identifying the proper lifecycle this * controller will run in. If not set the * {@link LifecycleFactory#DEFAULT_LIFECYCLE} will be used. * * @param lifecycleId * the lifecycle id for identifying the proper lifecycle */ public final void setLifecycleId(final String lifecycleId) { Assert.notNull(lifecycleId); this.lifecycleId = lifecycleId; } /** * Executes the faces lifecycle. * * @param request * current HTTP request * @param response * current HTTP response * @return a ModelAndView to render * @throws Exception * in case of errors */ protected final ModelAndView handleRequestInternal( final HttpServletRequest request, final HttpServletResponse response) throws Exception { FacesContext context = FacesContext.getCurrentInstance(); Assert.notNull(context); this.lifecycle.execute(context); return new ModelAndView(new DefaultFacesView()); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -