public void afterPhase(PhaseEvent event)
{
final FacesContext context = event.getFacesContext();
final ExternalContext exContext = context.getExternalContext();
final Map<String, Object> sessionMap = exContext.getSessionMap();
Map<String, JsfRequestSnapshot> aidMap
= (Map<String, JsfRequestSnapshot>) sessionMap.get(
"caucho.jsf.developer.aid");
if (aidMap == null) {
aidMap = new HashMap<String, JsfRequestSnapshot>();
sessionMap.put("caucho.jsf.developer.aid", aidMap);
}
try {
final UIViewRoot uiViewRoot = context.getViewRoot();
if (uiViewRoot != null) {
final String viewId = uiViewRoot.getViewId();
final String phaseId = event.getPhaseId().toString();
final ViewRoot viewRoot = (ViewRoot) reflect(context, uiViewRoot);
viewRoot.setPhase(phaseId);
//request attributes
Map<String, Object> requestMap = exContext.getRequestMap();
Map<String, Bean> requestSnapshot = new HashMap<String, Bean>();
for (String key : requestMap.keySet()) {
if (key.startsWith("caucho.") ||
key.startsWith("com.caucho.") ||
key.startsWith("javax."))
continue;
Bean bean = reflect(requestMap.get(key));
requestSnapshot.put(key, bean);
}
viewRoot.setRequestMap(requestSnapshot);
//session attributes
Map<String, Bean> sessionSnapshot = new HashMap<String, Bean>();
for (String key : sessionMap.keySet()) {
if (key.startsWith("caucho.") ||
key.startsWith("com.caucho.") ||
key.startsWith("javax."))
continue;
Bean bean = reflect(sessionMap.get(key));
sessionSnapshot.put(key, bean);
}
viewRoot.setSessionMap(sessionSnapshot);
//application attributes
Map<String, Object> applicationMap = exContext.getApplicationMap();
Map<String, Bean> applicationSnapshot = new HashMap<String, Bean>();
for (String key : applicationMap.keySet()) {
if (key.startsWith("caucho.") ||
key.startsWith("com.caucho.") ||
key.startsWith("javax."))
continue;
Bean bean = reflect(applicationMap.get(key));
applicationSnapshot.put(key, bean);
}
viewRoot.setApplicationMap(applicationSnapshot);
JsfRequestSnapshot snapshot;
if (PhaseId.RESTORE_VIEW.equals(event.getPhaseId())) {
snapshot = new JsfRequestSnapshot();
//headers
Map<String, String> map = exContext.getRequestHeaderMap();
snapshot.setHeaderMap(new HashMap<String, String>(map));
//parameters
map = exContext.getRequestParameterMap();
snapshot.setParameterMap(new HashMap<String, String>(map));
aidMap.put(viewId, snapshot);
}
else {