boolean restoreNonExcludedRequestAttributes = ((beganInPhase == Bridge.PortletPhase.ACTION_PHASE) ||
(beganInPhase == Bridge.PortletPhase.EVENT_PHASE) ||
(beganInPhase == Bridge.PortletPhase.RESOURCE_PHASE));
BridgeContext bridgeContext = BridgeContext.getCurrentInstance();
PortletPhase portletRequestPhase = bridgeContext.getPortletRequestPhase();
if (portletRequestPhase == Bridge.PortletPhase.RENDER_PHASE) {
if (!portletMode.equals(bridgeContext.getPortletRequest().getPortletMode())) {
setPortletModeChanged(true);
restoreNonExcludedRequestAttributes = false;
}
}
if ((beganInPhase == Bridge.PortletPhase.ACTION_PHASE) || (beganInPhase == Bridge.PortletPhase.EVENT_PHASE) ||
(beganInPhase == Bridge.PortletPhase.RESOURCE_PHASE)) {
// Restore the view root that may have been saved during the action/event/render phase of the portlet
// lifecycle.
UIViewRoot uiViewRoot = (UIViewRoot) getAttribute(BRIDGE_REQ_SCOPE_ATTR_FACES_VIEW_ROOT);
if (uiViewRoot != null) {
facesContext.setViewRoot(uiViewRoot);
logger.debug("Restored viewId=[{0}] uiViewRoot=[{1}]", uiViewRoot.getViewId(), uiViewRoot);
}
else {
logger.debug("Did not restore uiViewRoot");
}
// Restore the faces messages that may have been saved during the action/event/render phase of the portlet
// lifecycle.
List<FacesMessageWrapper> facesMessages = (List<FacesMessageWrapper>) getAttribute(
BRIDGE_REQ_SCOPE_ATTR_FACES_MESSAGES);
boolean restoredFacesMessages = false;
if (facesMessages != null) {
for (FacesMessageWrapper facesMessageWrapper : facesMessages) {
String clientId = facesMessageWrapper.getClientId();
FacesMessage facesMessage = facesMessageWrapper.getFacesMessage();
facesContext.addMessage(clientId, facesMessage);
logger.trace("Restored facesMessage=[{0}]", facesMessage.getSummary());
restoredFacesMessages = true;
}
}
if (restoredFacesMessages) {
logger.debug("Restored facesMessages");
}
else {
logger.debug("Did not restore any facesMessages");
}
// NOTE: PROPOSE-FOR-BRIDGE3-API: https://issues.apache.org/jira/browse/PORTLETBRIDGE-203 Restore the
// FacesContext attributes that may have been saved during the ACTION_PHASE of the portlet lifecycle.
restoreJSF2FacesContextAttributes(facesContext);
}
if (restoreNonExcludedRequestAttributes) {
// Restore the non-excluded request attributes.
List<RequestAttribute> savedRequestAttributes = (List<RequestAttribute>) getAttribute(
BRIDGE_REQ_SCOPE_ATTR_REQUEST_ATTRIBUTES);
boolean restoredNonExcludedRequestAttributes = false;
if (savedRequestAttributes != null) {
ExternalContext externalContext = facesContext.getExternalContext();
Map<String, Object> currentRequestAttributes = externalContext.getRequestMap();
// If a redirect did not occur, then restore the non-excluded request attributes.
if (!isRedirectOccurred()) {
for (RequestAttribute requestAttribute : savedRequestAttributes) {
String name = requestAttribute.getName();
Object value = requestAttribute.getValue();
logger.trace("Restoring non-excluded request attribute name=[{0}] value=[{1}]", name, value);
currentRequestAttributes.put(name, value);
restoredNonExcludedRequestAttributes = true;
}
}
}
if (restoredNonExcludedRequestAttributes) {
logger.debug("Restored non-excluded request attributes");
}
else {
logger.debug("Did not restore any non-excluded request attributes");
}
}
// If running in the RENDER_PHASE, then the Flash scope must be restored.
if (portletRequestPhase == Bridge.PortletPhase.RENDER_PHASE) {
// NOTE: PROPOSED-FOR-BRIDGE3-API: https://issues.apache.org/jira/browse/PORTLETBRIDGE-201
// Restore the flash scope.
ExternalContext externalContext = facesContext.getExternalContext();
restoreFlashState(externalContext);
// PROPOSE-FOR-BRIDGE3-API
restoreClientWindow(facesContext.getExternalContext());
}
// If running in the RENDER_PHASE, then the incongruity context must be restored.
if (((beganInPhase == Bridge.PortletPhase.ACTION_PHASE) || (beganInPhase == Bridge.PortletPhase.EVENT_PHASE)) &&
(portletRequestPhase == Bridge.PortletPhase.RENDER_PHASE)) {
List<IncongruityAttribute> savedIncongruityAttributes = (List<IncongruityAttribute>) getAttribute(
BRIDGE_REQ_SCOPE_ATTR_INCONGRUITY_CONTEXT_ATTRIBUTES);
if (savedIncongruityAttributes != null) {
IncongruityContext incongruityContext = bridgeContext.getIncongruityContext();
Map<String, Object> incongruityContextAttributes = incongruityContext.getAttributes();
for (IncongruityAttribute incongruityAttribute : savedIncongruityAttributes) {
String key = incongruityAttribute.getName();
Object value = incongruityAttribute.getValue();