1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts2.jsf;
22
23 import java.util.Map;
24
25 import javax.faces.application.NavigationHandler;
26 import javax.faces.context.FacesContext;
27
28 import com.opensymphony.xwork2.ActionContext;
29 import com.opensymphony.xwork2.config.entities.ActionConfig;
30 import com.opensymphony.xwork2.config.entities.ResultConfig;
31
32 /***
33 * Overrides the JFS navigation by delegating the result to handling by the core
34 * result code lookup and execution. If a result cannot be found, the previous
35 * NavigationHandler is called.
36 */
37 public class StrutsNavigationHandler extends NavigationHandler {
38
39 private NavigationHandler parent;
40
41 /***
42 * Creates the handler
43 *
44 * @param handler The old NavigationHandler to possibly delegate to
45 */
46 public StrutsNavigationHandler(NavigationHandler handler) {
47 this.parent = handler;
48 }
49
50 /***
51 * Stores any outcomes as the result code, failing over to the old
52 * NavigationHandler
53 *
54 * @param facesContext The faces context
55 * @param fromAction The action we are coming from
56 * @param outcome The String return code
57 */
58 @Override
59 public void handleNavigation(FacesContext facesContext, String fromAction, String outcome) {
60 ActionContext ctx = ActionContext.getContext();
61 if (outcome != null) {
62 ActionConfig config = ctx.getActionInvocation().getProxy().getConfig();
63 Map results = config.getResults();
64
65 ResultConfig resultConfig = null;
66
67 synchronized (config) {
68 try {
69 resultConfig = (ResultConfig) results.get(outcome);
70 } catch (NullPointerException e) {
71 }
72 if (resultConfig == null) {
73
74 resultConfig = (ResultConfig) results.get("*");
75 }
76 }
77 if (resultConfig != null) {
78 ctx.getActionInvocation().setResultCode(outcome);
79 } else {
80
81 parent.handleNavigation(facesContext, fromAction, outcome);
82 }
83 }
84 }
85
86 }