📄 simpleactioncontroller.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.controller;import java.util.Iterator;import java.util.List;import javax.faces.component.ActionSource;import javax.faces.component.UICommand;import javax.faces.context.FacesContext;import javax.faces.el.MethodBinding;import javax.faces.event.ActionEvent;import javax.faces.event.ActionListener;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.springframework.util.Assert;import org.springframework.web.servlet.ModelAndView;import org.springframework.web.servlet.View;import de.mindmatters.faces.application.ActionEventContextHolder;import de.mindmatters.faces.spring.context.servlet.FacesView;/** * This Controller implements an {@link ActionSource} and fullfills completely * the contract of an ActionSource. So this Controller can be used like a * {@link UICommand} which will be fully configured and mapped in the * {@link de.mindmatters.faces.spring.context.servlet.FacesDispatcherServlet}'s * application context. * * <p> * <em>For more information please have a look at the {@link UICommand} and * {@link ActionSource} documentations.</em> * </p> * * @author Andreas Kuhrwahl * */public class SimpleActionController extends AbstractFacesController implements ActionSource { /** The internal {@link ActionSource}. */ private ActionSource actionSource = new UICommand(); /** * {@inheritDoc} */ protected final ModelAndView handleRequestInternal( final FacesContext context, final HttpServletRequest request, final HttpServletResponse response) { ActionEvent event = ActionEventContextHolder.getActionEvent(); processAction(context, request, response, event); context.getApplication().getActionListener().processAction(event); View facesView = new FacesView(context.getViewRoot()); facesView = (View) getApplicationContext() .getAutowireCapableBeanFactory().initializeBean(facesView, context.getViewRoot().getViewId()); return new ModelAndView(facesView); } /** * Process the request. This method will be invoked after the * ActionListeners (added by {@link #setActionListeners(List)}) are * notified and before the Action and ActionListener {@link MethodBinding}s * of this {@link ActionSource} will be processed. May be overriden in * subclasses. * * @param context * {@link FacesContext} for the current request * @param request * current HTTP request * @param response * current HTTP response * @param event * current ActionEvent */ protected void processAction(final FacesContext context, final HttpServletRequest request, final HttpServletResponse response, final ActionEvent event) { } /** * Sets the {@link ActionSource} implementation this controller should use * as delegate. Default ActionSource is a {@link UICommand} instance. * * @param actionSource * the ActionSource to use for internal purposes. */ public final void setActionSource(final ActionSource actionSource) { Assert.notNull(actionSource); this.actionSource = actionSource; } /** * {@inheritDoc} */ public final void addActionListener(final ActionListener listener) { actionSource.addActionListener(listener); } /** * {@inheritDoc} */ public final MethodBinding getAction() { return actionSource.getAction(); } /** * {@inheritDoc} */ public final MethodBinding getActionListener() { return actionSource.getActionListener(); } /** * {@inheritDoc} */ public final ActionListener[] getActionListeners() { return actionSource.getActionListeners(); } /** * {@inheritDoc} */ public final boolean isImmediate() { return actionSource.isImmediate(); } /** * {@inheritDoc} */ public final void removeActionListener(final ActionListener listener) { actionSource.removeActionListener(listener); } /** * {@inheritDoc} */ public final void setAction(final MethodBinding action) { actionSource.setAction(action); } /** * {@inheritDoc} */ public final void setActionListener(final MethodBinding actionListener) { actionSource.setActionListener(actionListener); } /** * {@inheritDoc} */ public final void setImmediate(final boolean immediate) { actionSource.setImmediate(immediate); } /** * Sets the list of new {@link ActionListener}s interested in being * notified when {@link ActionEvent}s occur. * * @param actionListeners * the {@link ActionListener} instance to use */ public final void setActionListeners(final List actionListeners) { if (actionListeners != null) { for (Iterator i = actionListeners.iterator(); i.hasNext();) { addActionListener((ActionListener) i.next()); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -