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.faces.FacesException; |
22 | |
import javax.faces.application.Application; |
23 | |
import javax.faces.application.NavigationHandler; |
24 | |
import javax.faces.component.ActionSource; |
25 | |
import javax.faces.context.FacesContext; |
26 | |
import javax.faces.el.EvaluationException; |
27 | |
import javax.faces.el.MethodBinding; |
28 | |
import javax.faces.event.AbortProcessingException; |
29 | |
import javax.faces.event.ActionEvent; |
30 | |
import javax.faces.event.ActionListener; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | 0 | public class ActionListenerImpl |
39 | |
implements ActionListener |
40 | |
{ |
41 | |
|
42 | |
public void processAction(ActionEvent actionEvent) throws AbortProcessingException |
43 | |
{ |
44 | 0 | FacesContext facesContext = FacesContext.getCurrentInstance(); |
45 | 0 | Application application = facesContext.getApplication(); |
46 | |
|
47 | 0 | ActionSource actionSource = (ActionSource)actionEvent.getComponent(); |
48 | 0 | MethodBinding methodBinding = actionSource.getAction(); |
49 | |
|
50 | 0 | String fromAction = null; |
51 | 0 | String outcome = null; |
52 | 0 | if (methodBinding != null) |
53 | |
{ |
54 | 0 | fromAction = methodBinding.getExpressionString(); |
55 | |
try |
56 | |
{ |
57 | 0 | Object objOutcome = methodBinding.invoke(facesContext, null); |
58 | |
|
59 | 0 | if (objOutcome != null) |
60 | |
{ |
61 | 0 | outcome = objOutcome.toString(); |
62 | |
} |
63 | |
} |
64 | 0 | catch (EvaluationException e) |
65 | |
{ |
66 | 0 | Throwable cause = e.getCause(); |
67 | 0 | if (cause != null && cause instanceof AbortProcessingException) |
68 | |
{ |
69 | 0 | throw (AbortProcessingException)cause; |
70 | |
} |
71 | |
|
72 | 0 | throw new FacesException("Error calling action method of component with id " + actionEvent.getComponent().getClientId(facesContext), e); |
73 | |
|
74 | |
} |
75 | 0 | catch (RuntimeException e) |
76 | |
{ |
77 | 0 | throw new FacesException("Error calling action method of component with id " + actionEvent.getComponent().getClientId(facesContext), e); |
78 | 0 | } |
79 | |
} |
80 | |
|
81 | 0 | NavigationHandler navigationHandler = application.getNavigationHandler(); |
82 | 0 | navigationHandler.handleNavigation(facesContext, |
83 | |
fromAction, |
84 | |
outcome); |
85 | |
|
86 | 0 | facesContext.renderResponse(); |
87 | |
|
88 | 0 | } |
89 | |
} |