initRequest(request, wrappedResponse, Bridge.PortletPhase.RenderPhase);
String namespace = wrappedResponse.getNamespace();
StateId stateId = getStateHolder().getStateId(getPortletName(),
request, namespace);
PortletWindowState windowState = getStateHolder().getWindowState(
stateId);
if (null == windowState) {
windowState = new PortletWindowState() {
@Override
public BridgeConfig getBridgeConfig() {
return AjaxPortletBridge.this;
}
};
getStateHolder().addWindowState(stateId, windowState);
}
PortletBridgeContext bridgeContext = createBridgeContext(request,
windowState);
bridgeContext.setStateId(stateId);
FacesContext facesContext = getFacesContext(request, wrappedResponse);
try {
windowState.restoreRequest(facesContext, true);
// If we're using RichFaces, setup proper parameters for this render
// request
if (RICHFACES_ENABLED) {
setupAjaxParams(facesContext, stateId.toString(), namespace);
}
// set portletbridge title if its set.
ResourceBundle bundle = portletConfig.getResourceBundle(request
.getLocale());
if (bundle != null) {
String title = null;
try {
title = bundle.getString("javax.portlet.title");
wrappedResponse.setTitle(title);
} catch (Exception e) {
// Ignore MissingResourceException
}
}
try {
renderResponse(facesContext, windowState);
// TODO - detect redirect case. Reset response, clear request
// variables as far as Seam state.
// Perform new render phase with a new ViewId.
String redirectViewId = bridgeContext.getRedirectViewId();
if (null != redirectViewId) {
windowState.reset();
windowState.setViewId(redirectViewId);
Map<String, String[]> redirectParams = bridgeContext
.getRedirectRequestParameters();
// release old FacesContext.
facesContext.release();
// Reset attributes to initial state
Set<String> initialAttributes = bridgeContext
.getInitialRequestAttributeNames();
List<String> currentAttributes = Collections.list(request
.getAttributeNames());
currentAttributes.removeAll(initialAttributes);
for (Object newAttribute : currentAttributes) {
request.removeAttribute((String) newAttribute);
}
if (redirectParams != null) {
windowState.setRequestParameters(redirectParams);
}
// Create new FacesContext
facesContext = getFacesContext(request, wrappedResponse);
ViewHandler viewHandler = facesContext.getApplication()
.getViewHandler();
UIViewRoot viewRoot = viewHandler.createView(facesContext,
redirectViewId);
facesContext.setViewRoot(viewRoot);
renderResponse(facesContext, windowState);
}
windowState.setViewId(facesContext.getViewRoot().getViewId());
} catch (Exception e) {
wrappedResponse.reset();
log.log(Level.SEVERE, "Error processing execute lifecycle", e);
exceptionHandler.processRenderException(facesContext,
windowState, e);
}
// Set important Portal parameters to window state.
String viewId = facesContext.getViewRoot().getViewId();
//
String actionURL = facesContext.getApplication().getViewHandler()
.getActionURL(facesContext, viewId);
actionURL = facesContext.getExternalContext().encodeActionURL(
actionURL);
windowState.setPortalActionURL(new PortalActionURL(actionURL));
PortletURL portletURL = wrappedResponse.createRenderURL();
portletURL.setParameter(PortletStateHolder.STATE_ID_PARAMETER,
stateId.toString());
String renderUrl = portletURL.toString();
windowState.setPortalRenderURL(new PortalActionURL(renderUrl));
windowState.setNamespace(namespace);
windowState.setPortletLocale(request.getLocale());
// TODO - encode request attributes, portlet mode and windowId, as
// required by JSR-301 5.3.3
String portletModeName = request.getPortletMode().toString();
PortalActionURL historyViewId = new PortalActionURL(viewId);
historyViewId.setParameter(PortletStateHolder.STATE_ID_PARAMETER,
stateId.toString());
historyViewId.setParameter(Bridge.PORTLET_MODE_PARAMETER,
portletModeName);
facesContext.getExternalContext().getSessionMap().put(
VIEWID_HISTORY_PREFIX + portletModeName,
historyViewId.toString());
// writer.println("</div>");
windowState.saveSeamConversationId(facesContext);
// PortletSession portletSession = request.getPortletSession(true);
PortletSession portletSession = (PortletSession) facesContext
.getExternalContext().getSession(true);
WindowIDRetriver idRetriver = (WindowIDRetriver) portletSession
.getAttribute(PortletStateHolder.WINDOW_ID_RETRIVER);
if (null != idRetriver) {
windowState.setWindowId(idRetriver.getWindowID());
}
PortletBridgePrincipal security = new PortletBridgePrincipal(request,userRoles);
// TODO - get user roles, defined in the portletbridge.xml ( ???
// parse it ??? ), and store all values for a
// "isUserInRole(roleName)" calls