01: /*
02: * Copyright 2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.apache.myfaces.application;
17:
18: import javax.faces.FacesException;
19: import javax.faces.application.Application;
20: import javax.faces.application.NavigationHandler;
21: import javax.faces.component.ActionSource;
22: import javax.faces.context.FacesContext;
23: import javax.faces.el.EvaluationException;
24: import javax.faces.el.MethodBinding;
25: import javax.faces.event.AbortProcessingException;
26: import javax.faces.event.ActionEvent;
27: import javax.faces.event.ActionListener;
28:
29: /**
30: * @author Manfred Geiler (latest modification by $Author: dennisbyrne $)
31: * @author Anton Koinov
32: * @version $Revision: 511715 $ $Date: 2007-02-26 05:05:36 +0100 (Mo, 26 Feb 2007) $
33: */
34: public class ActionListenerImpl implements ActionListener {
35:
36: public void processAction(ActionEvent actionEvent)
37: throws AbortProcessingException {
38: FacesContext facesContext = FacesContext.getCurrentInstance();
39: Application application = facesContext.getApplication();
40:
41: ActionSource actionSource = (ActionSource) actionEvent
42: .getComponent();
43: MethodBinding methodBinding = actionSource.getAction();
44:
45: String fromAction = null;
46: String outcome = null;
47: if (methodBinding != null) {
48: fromAction = methodBinding.getExpressionString();
49: try {
50: Object objOutcome = methodBinding.invoke(facesContext,
51: null);
52:
53: if (objOutcome != null) {
54: outcome = objOutcome.toString();
55: }
56: } catch (EvaluationException e) {
57: Throwable cause = e.getCause();
58: if (cause != null
59: && cause instanceof AbortProcessingException) {
60: throw (AbortProcessingException) cause;
61: }
62:
63: throw new FacesException(
64: "Error calling action method of component with id "
65: + actionEvent.getComponent()
66: .getClientId(facesContext), e);
67:
68: } catch (RuntimeException e) {
69: throw new FacesException(
70: "Error calling action method of component with id "
71: + actionEvent.getComponent()
72: .getClientId(facesContext), e);
73: }
74: }
75:
76: NavigationHandler navigationHandler = application
77: .getNavigationHandler();
78: navigationHandler.handleNavigation(facesContext, fromAction,
79: outcome);
80: //Render Response if needed
81: facesContext.renderResponse();
82:
83: }
84: }
|