1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.seasar.teeda.core.util; |
17 | |
|
18 | |
import java.io.IOException; |
19 | |
import java.util.ArrayList; |
20 | |
import java.util.List; |
21 | |
import java.util.Map; |
22 | |
|
23 | |
import javax.faces.FacesException; |
24 | |
import javax.faces.application.NavigationHandler; |
25 | |
import javax.faces.context.ExternalContext; |
26 | |
import javax.faces.context.FacesContext; |
27 | |
import javax.faces.internal.scope.RedirectScope; |
28 | |
|
29 | |
import org.seasar.teeda.core.exception.AlreadyRedirectingException; |
30 | |
|
31 | |
public class NavigationHandlerUtil { |
32 | |
|
33 | 2 | private static final String KEY = NavigationHandlerUtil.class.getName(); |
34 | |
|
35 | 0 | private NavigationHandlerUtil() { |
36 | 0 | } |
37 | |
|
38 | |
public static void handleNavigation(FacesContext context, |
39 | |
String fromAction, String outCome) { |
40 | 1 | NavigationHandler handler = context.getApplication() |
41 | |
.getNavigationHandler(); |
42 | 1 | handler.handleNavigation(context, fromAction, outCome); |
43 | 1 | } |
44 | |
|
45 | |
public static void handleNoNavigation(FacesContext context) { |
46 | 0 | NavigationHandler handler = context.getApplication() |
47 | |
.getNavigationHandler(); |
48 | 0 | handler.handleNavigation(context, null, null); |
49 | 0 | } |
50 | |
|
51 | |
public static void redirect(FacesContext context, String path) { |
52 | 1 | RedirectScope.setRedirectingPath(context, path); |
53 | 1 | ExternalContext externalContext = context.getExternalContext(); |
54 | |
try { |
55 | 1 | externalContext.redirect(externalContext.encodeActionURL(path)); |
56 | 0 | } catch (IOException e) { |
57 | 0 | throw new FacesException(e.getMessage(), e); |
58 | 1 | } |
59 | 1 | context.responseComplete(); |
60 | 1 | context.renderResponse(); |
61 | 1 | } |
62 | |
|
63 | |
|
64 | |
public static void assertNotAlreadyRedirect(FacesContext context) { |
65 | 3 | Map scope = RedirectScope.getOrCreateContext(context); |
66 | 3 | List list = (List) scope.get(KEY); |
67 | 3 | if (list == null) { |
68 | 1 | list = new ArrayList(); |
69 | 1 | scope.put(KEY, list); |
70 | |
} |
71 | 3 | String viewId = context.getViewRoot().getViewId(); |
72 | 3 | if (list.contains(viewId)) { |
73 | 1 | throw new AlreadyRedirectingException(); |
74 | |
} |
75 | 2 | list.add(viewId); |
76 | 2 | } |
77 | |
} |