1 16 package org.apache.myfaces.application; 17 18 import org.apache.commons.logging.Log; 19 import org.apache.commons.logging.LogFactory; 20 21 import javax.faces.application.Application; 22 import javax.faces.application.NavigationHandler; 23 import javax.faces.component.ActionSource; 24 import javax.faces.context.FacesContext; 25 import javax.faces.el.EvaluationException; 26 import javax.faces.el.MethodBinding; 27 import javax.faces.event.AbortProcessingException; 28 import javax.faces.event.ActionEvent; 29 import javax.faces.event.ActionListener; 30 31 32 37 public class ActionListenerImpl 38 implements ActionListener 39 { 40 private static final Log log = LogFactory.getLog(ActionListenerImpl.class); 41 42 public void processAction(ActionEvent actionEvent) throws AbortProcessingException 43 { 44 FacesContext facesContext = FacesContext.getCurrentInstance(); 45 Application application = facesContext.getApplication(); 46 47 ActionSource actionSource = (ActionSource)actionEvent.getComponent(); 48 MethodBinding methodBinding = actionSource.getAction(); 49 50 String fromAction; 51 String outcome; 52 if (methodBinding == null) 53 { 54 fromAction = null; 55 outcome = null; 56 } 57 else 58 { 59 fromAction = methodBinding.getExpressionString(); 60 try 61 { 62 outcome = (String ) methodBinding.invoke(facesContext, null); 63 } 64 catch (EvaluationException e) 65 { 66 Throwable cause = e.getCause(); 67 if (cause != null && cause instanceof AbortProcessingException) 68 { 69 throw (AbortProcessingException)cause; 70 } 71 else 72 { 73 log.error("Error calling action method of component with id " + actionEvent.getComponent().getClientId(facesContext), e); 74 throw e; 75 } 76 } 77 catch (RuntimeException e) 78 { 79 log.error("Error calling action method of component with id " + actionEvent.getComponent().getClientId(facesContext), e); 80 throw e; 81 } 82 } 83 84 NavigationHandler navigationHandler = application.getNavigationHandler(); 85 navigationHandler.handleNavigation(facesContext, 86 fromAction, 87 outcome); 88 facesContext.renderResponse(); 90 91 } 92 } 93 | Popular Tags |