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.ConfigurableNavigationHandler; |
24 | |
import javax.faces.application.NavigationCase; |
25 | |
import javax.faces.application.NavigationHandler; |
26 | |
import javax.faces.component.ActionSource; |
27 | |
import javax.faces.component.ActionSource2; |
28 | |
import javax.faces.component.UIComponent; |
29 | |
import javax.faces.component.UIViewRoot; |
30 | |
import javax.faces.context.FacesContext; |
31 | |
import javax.faces.el.MethodBinding; |
32 | |
import javax.faces.event.AbortProcessingException; |
33 | |
import javax.faces.event.ActionEvent; |
34 | |
import javax.faces.event.ActionListener; |
35 | |
import javax.faces.event.PhaseId; |
36 | |
import org.apache.myfaces.view.facelets.ViewPoolProcessor; |
37 | |
import org.apache.myfaces.view.facelets.pool.ViewPool; |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | 0 | public class ActionListenerImpl implements ActionListener |
46 | |
{ |
47 | |
public void processAction(ActionEvent actionEvent) throws AbortProcessingException |
48 | |
{ |
49 | 0 | FacesContext facesContext = FacesContext.getCurrentInstance(); |
50 | 0 | Application application = facesContext.getApplication(); |
51 | 0 | UIComponent component = actionEvent.getComponent(); |
52 | |
|
53 | 0 | MethodExpression methodExpression = null; |
54 | 0 | MethodBinding methodBinding = null; |
55 | |
|
56 | 0 | String fromAction = null; |
57 | 0 | String outcome = null; |
58 | |
|
59 | 0 | if (component instanceof ActionSource2) |
60 | |
{ |
61 | |
|
62 | 0 | methodExpression = ((ActionSource2) component).getActionExpression(); |
63 | |
} |
64 | 0 | if (methodExpression == null && component instanceof ActionSource) |
65 | |
{ |
66 | |
|
67 | 0 | methodBinding = ((ActionSource) component).getAction(); |
68 | |
} |
69 | |
|
70 | 0 | if (methodExpression != null) |
71 | |
{ |
72 | 0 | fromAction = methodExpression.getExpressionString(); |
73 | |
|
74 | 0 | Object objOutcome = methodExpression.invoke(facesContext.getELContext(), null); |
75 | 0 | if (objOutcome != null) |
76 | |
{ |
77 | 0 | outcome = objOutcome.toString(); |
78 | |
} |
79 | |
|
80 | 0 | } |
81 | |
|
82 | 0 | else if (methodBinding != null) |
83 | |
{ |
84 | 0 | fromAction = methodBinding.getExpressionString(); |
85 | 0 | Object objOutcome = methodBinding.invoke(facesContext, null); |
86 | |
|
87 | 0 | if (objOutcome != null) |
88 | |
{ |
89 | 0 | outcome = objOutcome.toString(); |
90 | |
} |
91 | |
|
92 | |
} |
93 | |
|
94 | 0 | UIViewRoot root = facesContext.getViewRoot(); |
95 | 0 | ViewPoolProcessor processor = ViewPoolProcessor.getInstance(facesContext); |
96 | 0 | ViewPool pool = (processor != null) ? processor.getViewPool(facesContext, root) : null; |
97 | 0 | if (pool != null && pool.isDeferredNavigationEnabled() && |
98 | |
processor.isViewPoolStrategyAllowedForThisView(facesContext, root) && |
99 | |
(PhaseId.INVOKE_APPLICATION.equals(facesContext.getCurrentPhaseId()) || |
100 | |
PhaseId.APPLY_REQUEST_VALUES.equals(facesContext.getCurrentPhaseId())) ) |
101 | |
{ |
102 | 0 | NavigationHandler navigationHandler = application.getNavigationHandler(); |
103 | 0 | if (navigationHandler instanceof ConfigurableNavigationHandler) |
104 | |
{ |
105 | 0 | NavigationCase navigationCase = ((ConfigurableNavigationHandler) navigationHandler). |
106 | |
getNavigationCase(facesContext, fromAction, outcome); |
107 | 0 | if (navigationCase != null) |
108 | |
{ |
109 | |
|
110 | 0 | if (!facesContext.getAttributes().containsKey(ViewPoolProcessor.INVOKE_DEFERRED_NAVIGATION)) |
111 | |
{ |
112 | 0 | String toFlowDocumentId = (component != null) ? |
113 | |
(String) component.getAttributes().get(ActionListener.TO_FLOW_DOCUMENT_ID_ATTR_NAME) : null; |
114 | 0 | if (toFlowDocumentId != null) |
115 | |
{ |
116 | 0 | facesContext.getAttributes().put(ViewPoolProcessor.INVOKE_DEFERRED_NAVIGATION, |
117 | |
new Object[]{fromAction, outcome, toFlowDocumentId}); |
118 | |
} |
119 | |
else |
120 | |
{ |
121 | 0 | facesContext.getAttributes().put(ViewPoolProcessor.INVOKE_DEFERRED_NAVIGATION, |
122 | |
new Object[]{fromAction, outcome}); |
123 | |
} |
124 | |
} |
125 | |
} |
126 | |
} |
127 | 0 | } |
128 | |
else |
129 | |
{ |
130 | 0 | NavigationHandler navigationHandler = application.getNavigationHandler(); |
131 | 0 | String toFlowDocumentId = (component != null) ? |
132 | |
(String) component.getAttributes().get(ActionListener.TO_FLOW_DOCUMENT_ID_ATTR_NAME) : null; |
133 | |
|
134 | 0 | if (toFlowDocumentId != null) |
135 | |
{ |
136 | 0 | navigationHandler.handleNavigation(facesContext, fromAction, outcome, toFlowDocumentId); |
137 | |
} |
138 | |
else |
139 | |
{ |
140 | 0 | navigationHandler.handleNavigation(facesContext, fromAction, outcome); |
141 | |
} |
142 | |
|
143 | 0 | facesContext.renderResponse(); |
144 | |
} |
145 | 0 | } |
146 | |
} |