1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.application;
20
21 import javax.el.MethodExpression;
22 import javax.faces.application.Application;
23 import javax.faces.application.NavigationHandler;
24 import javax.faces.component.ActionSource;
25 import javax.faces.component.ActionSource2;
26 import javax.faces.component.UIComponent;
27 import javax.faces.context.FacesContext;
28 import javax.faces.el.MethodBinding;
29 import javax.faces.event.AbortProcessingException;
30 import javax.faces.event.ActionEvent;
31 import javax.faces.event.ActionListener;
32
33
34
35
36
37
38
39 public class ActionListenerImpl implements ActionListener
40 {
41 public void processAction(ActionEvent actionEvent) throws AbortProcessingException
42 {
43 FacesContext facesContext = FacesContext.getCurrentInstance();
44 Application application = facesContext.getApplication();
45 UIComponent component = actionEvent.getComponent();
46
47 MethodExpression methodExpression = null;
48 MethodBinding methodBinding = null;
49
50 String fromAction = null;
51 String outcome = null;
52
53 if (component instanceof ActionSource2)
54 {
55
56 methodExpression = ((ActionSource2) component).getActionExpression();
57 }
58 if (methodExpression == null && component instanceof ActionSource)
59 {
60
61 methodBinding = ((ActionSource) component).getAction();
62 }
63
64 if (methodExpression != null)
65 {
66 fromAction = methodExpression.getExpressionString();
67
68 Object objOutcome = methodExpression.invoke(facesContext.getELContext(), null);
69 if (objOutcome != null)
70 {
71 outcome = objOutcome.toString();
72 }
73
74 }
75
76 else if (methodBinding != null)
77 {
78 fromAction = methodBinding.getExpressionString();
79 Object objOutcome = methodBinding.invoke(facesContext, null);
80
81 if (objOutcome != null)
82 {
83 outcome = objOutcome.toString();
84 }
85
86 }
87
88 NavigationHandler navigationHandler = application.getNavigationHandler();
89 navigationHandler.handleNavigation(facesContext, fromAction, outcome);
90
91 facesContext.renderResponse();
92
93 }
94 }