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