⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 actioneventcontextholder.java

📁 Please read your package and describe it at least 40 bytes in English. System will automatically de
💻 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 javax.faces.event.ActionEvent;/** * Simple holder class that associates a <strong>{@link ActionEventContext}</strong> * instance with the current thread. The ActionEventContext will be inherited by * any child threads spawned by the current thread. *  * <p> * Used as a central holder for the current ActionEvent in JSF-Spring, wherever * necessary: for example, in concrete controller instances. <strong>{@link DelegatingActionListener}</strong> * automatically exposes its current ActionEvent here. * </p> *  * @author Andreas Kuhrwahl * @see DelegatingActionListener#processAction(ActionEvent) *  */public final class ActionEventContextHolder {    /** Holds the context. */    private static final ThreadLocal ACTION_EVENT_CONTEXT_HOLDER = new InheritableThreadLocal();    /**     * It's a static class.     */    private ActionEventContextHolder() {        super();    }    /**     * Associate the given ActionEventContext with the current thread.     *      * @param actionEventContext     *            the current ActionEventContext, or <code>null</code> to     *            reset the thread-bound context     */    public static void setActionEventContext(            final ActionEventContext actionEventContext) {        ACTION_EVENT_CONTEXT_HOLDER.set(actionEventContext);    }    /**     * Return the ActionEventContext associated with the current thread, if any.     *      * @return the current ActionEventContext, or <code>null</code> if none     */    public static ActionEventContext getActionEventContext() {        return (ActionEventContext) ACTION_EVENT_CONTEXT_HOLDER.get();    }    /**     * Associate the given ActionEvent with the current thread. Will implicitly     * create a ActionEventContext for the given ActionEvent.     *      * @param actionEvent     *            the current ActionEvent, or <code>null</code> to reset the     *            thread-bound context     * @see SimpleActionEventContext#SimpleActionEventContext(ActionEvent)     */    public static void setActionEvent(final ActionEvent actionEvent) {        ActionEventContext actionEventContext = null;        if (actionEvent != null) {            actionEventContext = new SimpleActionEventContext(actionEvent);        }        ACTION_EVENT_CONTEXT_HOLDER.set(actionEventContext);    }    /**     * Return the ActionEvent associated with the current thread, if any.     *      * @return the current ActionEvent, or <code>null</code> if no specific     *         ActionEvent has been associated with the current thread     * @see ActionEventContext#getActionEvent()     */    public static ActionEvent getActionEvent() {        ActionEvent actionEvent = null;        ActionEventContext actionEventContext = (ActionEventContext) ACTION_EVENT_CONTEXT_HOLDER                .get();        if (actionEventContext != null) {            actionEvent = actionEventContext.getActionEvent();        }        return actionEvent;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -