1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.lifecycle; |
20 | |
|
21 | |
import java.util.Map; |
22 | |
|
23 | |
import javax.el.ValueExpression; |
24 | |
import javax.faces.FacesException; |
25 | |
import javax.faces.application.ViewHandler; |
26 | |
import javax.faces.component.UIComponent; |
27 | |
import javax.faces.context.ExternalContext; |
28 | |
import javax.faces.context.FacesContext; |
29 | |
import javax.faces.render.ResponseStateManager; |
30 | |
|
31 | |
import org.apache.commons.logging.Log; |
32 | |
import org.apache.commons.logging.LogFactory; |
33 | |
import org.apache.myfaces.shared_impl.renderkit.RendererUtils; |
34 | |
import org.apache.myfaces.shared_impl.util.Assert; |
35 | |
import org.apache.myfaces.shared_impl.util.RestoreStateUtils; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | 0 | public class DefaultRestoreViewSupport implements RestoreViewSupport |
42 | |
{ |
43 | |
private static final String JAVAX_SERVLET_INCLUDE_SERVLET_PATH = "javax.servlet.include.servlet_path"; |
44 | |
|
45 | |
private static final String JAVAX_SERVLET_INCLUDE_PATH_INFO = "javax.servlet.include.path_info"; |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
private static final String PORTLET_LIFECYCLE_PHASE = "javax.portlet.faces.phase"; |
52 | |
|
53 | 0 | private final Log log = LogFactory.getLog(DefaultRestoreViewSupport.class); |
54 | |
|
55 | |
public void processComponentBinding(FacesContext facesContext, UIComponent component) |
56 | |
{ |
57 | 0 | ValueExpression binding = component.getValueExpression("binding"); |
58 | 0 | if (binding != null) |
59 | |
{ |
60 | 0 | binding.setValue(facesContext.getELContext(), component); |
61 | |
} |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | 0 | RestoreStateUtils.recursivelyHandleComponentReferencesAndSetValid(facesContext,component); |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | 0 | } |
75 | |
|
76 | |
public String calculateViewId(FacesContext facesContext) |
77 | |
{ |
78 | 0 | Assert.notNull(facesContext); |
79 | 0 | ExternalContext externalContext = facesContext.getExternalContext(); |
80 | 0 | Map<String, Object> requestMap = externalContext.getRequestMap(); |
81 | |
|
82 | 0 | String viewId = null; |
83 | 0 | boolean traceEnabled = log.isTraceEnabled(); |
84 | |
|
85 | 0 | if (requestMap.containsKey(PORTLET_LIFECYCLE_PHASE)) |
86 | |
{ |
87 | 0 | viewId = (String) externalContext.getRequestPathInfo(); |
88 | |
} |
89 | |
else |
90 | |
{ |
91 | 0 | viewId = (String) requestMap.get(JAVAX_SERVLET_INCLUDE_PATH_INFO); |
92 | 0 | if (viewId != null) |
93 | |
{ |
94 | 0 | if (traceEnabled) |
95 | |
{ |
96 | 0 | log.trace("Calculated viewId '" + viewId + "' from request param '" + JAVAX_SERVLET_INCLUDE_PATH_INFO |
97 | |
+ "'"); |
98 | |
} |
99 | |
} |
100 | |
else |
101 | |
{ |
102 | 0 | viewId = externalContext.getRequestPathInfo(); |
103 | 0 | if (viewId != null && traceEnabled) |
104 | |
{ |
105 | 0 | log.trace("Calculated viewId '" + viewId + "' from request path info"); |
106 | |
} |
107 | |
} |
108 | |
|
109 | 0 | if (viewId == null) |
110 | |
{ |
111 | 0 | viewId = (String) requestMap.get(JAVAX_SERVLET_INCLUDE_SERVLET_PATH); |
112 | 0 | if (viewId != null && traceEnabled) |
113 | |
{ |
114 | 0 | log.trace("Calculated viewId '" + viewId + "' from request param '" |
115 | |
+ JAVAX_SERVLET_INCLUDE_SERVLET_PATH + "'"); |
116 | |
} |
117 | |
} |
118 | |
} |
119 | |
|
120 | 0 | if (viewId == null) |
121 | |
{ |
122 | 0 | viewId = externalContext.getRequestServletPath(); |
123 | 0 | if (viewId != null && traceEnabled) |
124 | |
{ |
125 | 0 | log.trace("Calculated viewId '" + viewId + "' from request servlet path"); |
126 | |
} |
127 | |
} |
128 | |
|
129 | 0 | if (viewId == null) |
130 | |
{ |
131 | 0 | throw new FacesException("Could not determine view id."); |
132 | |
} |
133 | |
|
134 | 0 | return viewId; |
135 | |
} |
136 | |
|
137 | |
public boolean isPostback(FacesContext facesContext) |
138 | |
{ |
139 | 0 | ViewHandler viewHandler = facesContext.getApplication().getViewHandler(); |
140 | 0 | String renderkitId = viewHandler.calculateRenderKitId(facesContext); |
141 | 0 | ResponseStateManager rsm = RendererUtils.getResponseStateManager(facesContext, renderkitId); |
142 | 0 | return rsm.isPostback(facesContext); |
143 | |
} |
144 | |
} |