📄 delegatingactionlistener.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.application;import java.util.Map;import javax.faces.context.FacesContext;import javax.faces.event.ActionEvent;import javax.faces.event.ActionListener;import org.springframework.util.Assert;/** * This action listener implementation processes action events during the * <em>Apply Request Values</em> or <em>Invoke Application</em> phase of the * request processing lifecycle (depending upon the <code>immediate</code> * property of the {@link javax.faces.component.ActionSource} that queued this * event. * * <p> * Usually this action listener invokes the specified application action method * of the encapsulated action listener of the underlying JSF implementation. * <strong>But</strong> if there can be found an action listener in the request * the action method of this one will be invoked. * </p> * * <p> * Furthermore this action listener populates the action event given to the * action method as a thread local variable via the * {@link ActionEventContextHolder}. * </p> * * @author Andreas Kuhrwahl * @see ActionEventContext * @see ActionEventContextHolder * */public final class DelegatingActionListener implements ActionListener { /** The request key of the delegate. */ private static final String ACTION_LISTENER_DELEGATE = DelegatingActionListener.class .getName(); /** * The original action listener of the underlying JSF implementation. */ private final ActionListener orig; /** * Creates an ApplicationListener with the given action listener * <code>orig</code> of the underlying JSF implementation. * * @param orig * the original action listener of the underlying JSF * implementation */ public DelegatingActionListener(final ActionListener orig) { super(); this.orig = orig; } /** * Associate the given ActionListener with the current thread. Will be used * from {@link DelegatingActionListener}. * * @param context * {@link FacesContext} for the current request * @param actionListener * the current ActionListener */ public static void bindActionListener(final FacesContext context, final ActionListener actionListener) { Assert.notNull(context); Assert.notNull(actionListener); Map requestMap = context.getExternalContext().getRequestMap(); Assert.isNull(requestMap.get(ACTION_LISTENER_DELEGATE)); requestMap.put(ACTION_LISTENER_DELEGATE, actionListener); } /** * {@inheritDoc} */ public void processAction(final ActionEvent event) { ActionEventContextHolder.setActionEvent(event); try { ActionListener delegate = (ActionListener) FacesContext .getCurrentInstance().getExternalContext().getRequestMap() .remove(ACTION_LISTENER_DELEGATE); if (delegate == null) { delegate = this.orig; } delegate.processAction(event); } finally { ActionEventContextHolder.setActionEvent(null); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -