📄 actionmethodnameresolver.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 javax.faces.component.ActionSource;import javax.faces.context.FacesContext;import javax.faces.el.MethodBinding;import javax.faces.event.ActionEvent;import javax.servlet.http.HttpServletRequest;import org.springframework.web.servlet.mvc.multiaction.MethodNameResolver;import org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException;import de.mindmatters.faces.application.ActionEventContextHolder;/** * Simple implementation of MethodNameResolver that maps JSF Action outcomes to * method names. This class is the default implementation used by the * {@link MultiActionEventController} class. * * <p> * This class invokes the {@link MethodBinding} from the {@link ActionSource} * exposed from the current {@link ActionEvent} and maps the evaluated outcome * to a method name. * </p> * * <p> * Examples: * <ul> * <li><code><h:commandButton action="foo".../></code> evaluates to * method name 'foo'</li> * <li><code><h:commandButton action="#{foo.bar}".../></code> invokes * method bar on object foo and returns an outcome (a String) which will be used * as method name</li> * </ul> * </p> * * @author Andreas Kuhrwahl * */public final class ActionMethodNameResolver implements MethodNameResolver { /** * {@inheritDoc} */ public String getHandlerMethodName(final HttpServletRequest request) throws NoSuchRequestHandlingMethodException { ActionEvent event = ActionEventContextHolder.getActionEvent(); if (event == null) { throw new NoSuchRequestHandlingMethodException(request); } String methodName = null; MethodBinding mb = ((ActionSource) event.getComponent()).getAction(); if (mb != null) { try { methodName = (String) mb.invoke(FacesContext .getCurrentInstance(), null); } catch (Exception ex) { methodName = null; } } if (methodName == null) { throw new NoSuchRequestHandlingMethodException(request); } return methodName; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -