use of javax.portlet.faces.BridgeInvalidViewPathException in project liferay-faces-bridge-impl by liferay.
the class BridgePhaseHeaderRenderCommon method executeRender.
protected void executeRender(String renderRedirectViewId, Bridge.PortletPhase portletPhase) throws BridgeException, IOException {
RenderRequest renderRequest = getRenderRequest();
MimeResponse mimeResponse = getMimeResponse();
init(renderRequest, mimeResponse, portletPhase);
// Determine whether or not the Faces lifecycle was already executed.
boolean facesLifecycleExecuted = bridgeRequestScope.isFacesLifecycleExecuted();
// Restore the faces view root and messages that would have been saved during the ACTION_PHASE.
bridgeRequestScope.restoreState(facesContext);
// scope must not be maintained if a redirect has occurred.
if (bridgeRequestScope.isPortletModeChanged() || bridgeRequestScope.isRedirectOccurred()) {
bridgeRequestScopeCache.removeValue(bridgeRequestScope.getId());
}
// in the FacesContext.
if (renderRedirectViewId != null) {
renderRequest.setAttribute(BridgeExt.RENDER_REDIRECT_AFTER_DISPATCH, Boolean.TRUE);
ViewHandler viewHandler = facesContext.getApplication().getViewHandler();
UIViewRoot uiViewRoot = viewHandler.createView(facesContext, renderRedirectViewId);
facesContext.setViewRoot(uiViewRoot);
logger.debug("Performed render-redirect to viewId=[{0}]", renderRedirectViewId);
} else // _facesViewIdRender request parameter.
if (bridgeRequestScope.isRedirectOccurred()) {
// TCK (redirectEventTest)
facesLifecycleExecuted = false;
}
// http://javaserverfaces.java.net/nonav/docs/2.0/javadocs/javax/faces/context/FacesContext.html#isPostback()
if (bridgeRequestScope.getBeganInPhase() == Bridge.PortletPhase.ACTION_PHASE) {
ExternalContext externalContext = facesContext.getExternalContext();
externalContext.getRequestMap().put(Bridge.IS_POSTBACK_ATTRIBUTE, Boolean.TRUE);
}
logger.debug("portletName=[{0}] facesLifecycleExecuted=[{1}]", portletName, facesLifecycleExecuted);
// If the JSF lifecycle executed back in the ACTION_PHASE of the portlet lifecycle, then
if (facesLifecycleExecuted) {
// TCK: prpUpdatedFromActionTest
PhaseEvent restoreViewPhaseEvent = new PhaseEvent(facesContext, PhaseId.RESTORE_VIEW, facesLifecycle);
PhaseListener[] phaseListeners = facesLifecycle.getPhaseListeners();
for (PhaseListener phaseListener : phaseListeners) {
if (phaseListener instanceof IPCPhaseListener) {
phaseListener.afterPhase(restoreViewPhaseEvent);
break;
}
}
} else // Otherwise, in accordance with Section 5.2.6 of the Spec, execute the JSF lifecycle so that ONLY the
// RESTORE_VIEW phase executes. Note that this is accomplished by the HeaderRequestPhaseListener.
{
ExternalContext externalContext = facesContext.getExternalContext();
try {
String viewId = getFacesViewId(externalContext);
logger.debug("Executing Faces lifecycle for viewId=[{0}]", viewId);
}// lifecycle has already happened in the HEADER_PHASE.
catch (BridgeException e) {
// TCK (portletSetsInvalidViewPathTest)
// TCK (exceptionThrownWhenNoDefaultViewIdTest)
Writer responseOutputWriter = getResponseOutputWriter(externalContext);
if (responseOutputWriter instanceof CapturingWriter) {
CapturingWriter capturingWriter = (CapturingWriter) responseOutputWriter;
renderRequest.setAttribute(Bridge.RENDER_RESPONSE_OUTPUT, capturingWriter.getWriterOperations());
}
logger.error("Unable to get viewId due to {0}", e.getClass().getSimpleName());
if (e instanceof BridgeInvalidViewPathException) {
renderRequest.setAttribute(HANDLING_BRIDGE_INVALID_VIEW_PATH_EXCEPTION, true);
queueHandleableException(renderRequest, facesContext, e);
} else {
throw e;
}
}
// Attach the JSF 2.2 client window to the JSF lifecycle so that Faces Flows can be utilized.
attachClientWindowToLifecycle(facesContext, facesLifecycle);
// Execute the JSF lifecycle.
if (isHandlingBridgeInvalidViewPathException(renderRequest)) {
try {
facesLifecycle.execute(facesContext);
} catch (FacesException e) {
Throwable cause = e.getCause();
if ((cause != null) && (cause instanceof BridgeInvalidViewPathException)) {
throw (BridgeException) cause;
} else {
throw e;
}
} finally {
renderRequest.removeAttribute(HANDLING_BRIDGE_INVALID_VIEW_PATH_EXCEPTION);
}
} else {
facesLifecycle.execute(facesContext);
}
}
throwQueuedExceptionIfNecessary(facesContext);
// UIViewRoot.
if (bridgeRequestScope.isPortletModeChanged() && !bridgeRequestScope.isNavigationOccurred()) {
BridgeNavigationHandler bridgeNavigationHandler = getBridgeNavigationHandler(facesContext);
PortletMode fromPortletMode = bridgeRequestScope.getPortletMode();
PortletMode toPortletMode = renderRequest.getPortletMode();
bridgeNavigationHandler.handleNavigation(facesContext, fromPortletMode, toPortletMode);
}
// Determines whether or not lifecycle incongruities should be managed.
boolean manageIncongruities = PortletConfigParam.ManageIncongruities.getBooleanValue(portletConfig);
// lifecycle.
if (manageIncongruities) {
incongruityContext.makeCongruous(facesContext);
}
// Execute the RENDER_RESPONSE phase of the faces lifecycle.
logger.debug("Executing Faces render");
facesLifecycle.render(facesContext);
// Set the view history according to Section 5.4.3 of the Bridge Spec.
setViewHistory(facesContext.getViewRoot().getViewId());
// Spec 6.6 (Namespacing)
indicateNamespacingToConsumers(facesContext.getViewRoot(), mimeResponse);
// If a render-redirect occurred, then
ExternalContext externalContext = facesContext.getExternalContext();
Map<String, Object> requestMap = externalContext.getRequestMap();
Boolean renderRedirect = (Boolean) requestMap.remove(BridgeExt.RENDER_REDIRECT);
Writer responseOutputWriter = getResponseOutputWriter(externalContext);
if ((renderRedirect != null) && renderRedirect) {
// Cleanup the old FacesContext since a new one will be created in the recursive method call below.
facesContext.responseComplete();
facesContext.release();
// redirect URL.
if (responseOutputWriter instanceof CapturingWriter) {
CapturingWriter capturingWriter = (CapturingWriter) responseOutputWriter;
capturingWriter.getWriterOperations().clear();
}
// Recursively call this method with the render-redirect URL so that the RENDER_RESPONSE phase of the
// JSF lifecycle will be re-executed according to the new Faces viewId found in the redirect URL.
renderRedirectViewId = (String) requestMap.remove(BridgeExt.RENDER_REDIRECT_VIEW_ID);
executeRender(renderRedirectViewId, portletPhase);
} else // Otherwise,
{
// HEADER_PHASE or that a render-redirect executed in the HEADER_PHASE or RESOURCE_PHASE.
if (responseOutputWriter instanceof CapturingWriter) {
CapturingWriter capturingWriter = (CapturingWriter) responseOutputWriter;
List<WriterOperation> writerOperations = capturingWriter.getWriterOperations();
if (writerOperations != null) {
// that the markup will be written to the response.
if (portletPhase == Bridge.PortletPhase.RENDER_PHASE) {
for (WriterOperation writerOperation : writerOperations) {
writerOperation.invoke(responseOutputWriter);
}
} else // Otherwise, since running in the HEADER_PHASE, save the list of writer operations so that the
// markup will be rendered in the subsequent RENDER_PHASE.
{
renderRequest.setAttribute(Bridge.RENDER_RESPONSE_OUTPUT, writerOperations);
}
}
}
}
}
use of javax.portlet.faces.BridgeInvalidViewPathException in project liferay-faces-bridge-impl by liferay.
the class PortletSetsViewTestPortlet method renderView.
@Override
public void renderView(RenderRequest renderRequest, MimeResponse mimeResponse) throws PortletException, IOException {
if (getTestName().equals(SETSVIEWID_TEST)) {
renderRequest.setAttribute(Bridge.VIEW_ID, "/tests/portletSetsViewIdTestSuccess.xhtml");
dispatchToView(renderRequest, mimeResponse);
} else if (getTestName().equals(SETSVIEWPATH_TEST)) {
renderRequest.setAttribute(Bridge.VIEW_PATH, "/tests/portletSetsViewIdTestSuccess.jsf");
dispatchToView(renderRequest, mimeResponse);
} else if (getTestName().equals(SETSINVALIDVIEWPATH_TEST)) {
renderRequest.setAttribute(Bridge.VIEW_PATH, "/tests/InvalidViewPath.jsp");
Bridge bridge = super.getFacesBridge(renderRequest, mimeResponse);
try {
doBridgeFacesRequest(bridge, renderRequest, mimeResponse);
outputInvalidViewPathTestResult(renderRequest, mimeResponse, false);
} catch (BridgeInvalidViewPathException e) {
outputInvalidViewPathTestResult(renderRequest, mimeResponse, true);
} catch (Exception e) {
outputInvalidViewPathTestResult(renderRequest, mimeResponse, false);
}
}
}
use of javax.portlet.faces.BridgeInvalidViewPathException in project liferay-faces-bridge-impl by liferay.
the class BridgePhaseCompat_2_0_Impl method throwQueuedExceptionIfNecessary.
protected void throwQueuedExceptionIfNecessary(FacesContext facesContext) throws BridgeException {
// If there were any "handled" exceptions queued, then throw a BridgeException.
ExceptionHandler exceptionHandler = facesContext.getExceptionHandler();
Throwable t = getQueuedException(exceptionHandler, true);
if (t == null) {
// Otherwise, if there were any "unhandled" exceptions queued, then throw a BridgeException.
t = getQueuedException(exceptionHandler, false);
}
if (t != null) {
if (t instanceof BridgeException) {
throw (BridgeException) t;
} else {
Throwable cause = t.getCause();
if ((cause != null) && (cause instanceof BridgeInvalidViewPathException)) {
throw (BridgeException) cause;
} else {
throw new BridgeException(t);
}
}
}
}
use of javax.portlet.faces.BridgeInvalidViewPathException in project liferay-faces-bridge-impl by liferay.
the class ExternalContextImpl method getFacesViewIdAndQueryString.
/**
* <p>This method returns the target view (and optional query string) as described in section 5.2.3 of the Bridge
* Spec titled "Determining the Target View".</p>
*
* <p>Try#1: Get the viewId from the {@link Bridge#VIEW_ID} (javax.portlet.faces.viewId) request attribute. As
* described in sections 3.4 and 4.2.5 of the bridge spec, this attribute is set by the {@link GenericFacesPortlet}
* when it encounters the {@link Bridge#FACES_VIEW_ID_PARAMETER} request parameter.</p>
*
* <p>Try#2: Get the viewId from the {@link Bridge#VIEW_PATH} (javax.portlet.faces.viewPath) request attribute. As
* described in sections 3.4 and 4.2.5 of the bridge spec, this attribute is set by the {@link GenericFacesPortlet}
* when it encounters the {@link Bridge#FACES_VIEW_PATH_PARAMETER} request parameter. If the viewId cannot be
* determined, then {@link BridgeInvalidViewPathException} is thrown.</p>
*
* <p>Try#3: Get the viewId from a prior render-redirect (if one has occurred).</p>
*
* <p>Try#4: Get the viewId from a request parameter, the name of which is dynamic depending on the {@link
* Bridge.PortletPhase}.</p>
*
* <p>Try#5:Get the viewId from the init-param value in the portlet.xml descriptor according the current {@link
* PortletMode}.</p>
*
* @throws BridgeDefaultViewNotSpecifiedException when the default view is not specified in the
* WEB-INF/portlet.xml descriptor.
* @throws BridgeInvalidViewPathException when the {@link Bridge#VIEW_PATH} request attribute contains an
* invalid path such that the target view cannot be determined.
*/
protected String getFacesViewIdAndQueryString() throws BridgeDefaultViewNotSpecifiedException, BridgeInvalidViewPathException {
if (viewIdAndQueryString == null) {
// Try#1: Get the viewId the "javax.portlet.faces.viewId" request attribute.
if (PortletConfigParam.ViewIdParameterEnabled.getBooleanValue(portletConfig)) {
viewIdAndQueryString = getFacesViewIdRequestAttribute(Bridge.VIEW_ID);
}
if (viewIdAndQueryString == null) {
// Try#2: Get the viewId from the "javax.portlet.faces.viewPath" request attribute.
String viewPath = null;
if (PortletConfigParam.ViewPathParameterEnabled.getBooleanValue(portletConfig)) {
viewPath = getFacesViewIdRequestAttribute(Bridge.VIEW_PATH);
}
if (viewPath != null) {
// If present, remove the query string from the specified viewPath.
int pos = viewPath.indexOf("?");
if (pos > 0) {
viewPath = viewPath.substring(0, pos);
}
// If present, remove everything up to (and including) the context path from the viewPath.
String contextPath = portletRequest.getContextPath();
pos = viewPath.indexOf(contextPath);
if (pos >= 0) {
viewPath = viewPath.substring(pos + contextPath.length());
}
if (!viewPath.startsWith("/")) {
viewPath = "/" + viewPath;
}
viewIdAndQueryString = getFacesViewIdFromPath(viewPath);
if (viewIdAndQueryString == null) {
throw new BridgeInvalidViewPathException();
}
}
if (viewIdAndQueryString == null) {
// Try #3: Get the viewId from a prior render-redirect (if one has occurred). Note that this logic
// depends on the BridgePhaseRenderImpl calling the setRenderRedirectURL(BridgeRedirectURL) method
// on this class instance when a render-redirect takes place.
String renderRedirectViewId = (String) portletRequest.getAttribute(BridgeExt.RENDER_REDIRECT_VIEW_ID);
if (renderRedirectViewId != null) {
viewIdAndQueryString = renderRedirectViewId;
}
if (viewIdAndQueryString == null) {
// Try#4: Get the viewId from a request parameter, the name of which is dynamic depending on
// the portlet phase.
String requestParameterName = null;
if ((portletPhase == Bridge.PortletPhase.RESOURCE_PHASE) && PortletConfigParam.ViewIdResourceParameterEnabled.getBooleanValue(portletConfig)) {
requestParameterName = bridgeConfig.getViewIdResourceParameterName();
} else if (PortletConfigParam.ViewIdRenderParameterEnabled.getBooleanValue(portletConfig)) {
requestParameterName = bridgeConfig.getViewIdRenderParameterName();
}
if (requestParameterName != null) {
viewIdAndQueryString = getFacesViewIdRequestParameter(requestParameterName);
}
if (viewIdAndQueryString == null) {
// Try#5: Get the viewId from the init-param value in the portlet.xml descriptor according
// to the current portlet mode.
PortletMode currentPortletMode = portletRequest.getPortletMode();
// a JSF 2 resource URL.
if (PortletMode.UNDEFINED.equals(currentPortletMode)) {
logger.debug("Unable to get the default view for portletMode=undefined");
} else // Otherwise, determine the default view according to the portlet mode. If it can't be
// determined then throw BridgeDefaultViewNotSpecifiedException according to Section 5.2.3
// of the FacesBridge Spec.
{
viewIdAndQueryString = getDefaultViewIdMap(portletConfig).get(currentPortletMode.toString());
logger.debug("portlet.xml viewId=[{0}] portletMode=[{1}]", viewIdAndQueryString, currentPortletMode);
if (viewIdAndQueryString == null) {
throw new BridgeDefaultViewNotSpecifiedException();
}
}
} else {
logger.debug("request parameter {0}=[{1}]", requestParameterName, viewIdAndQueryString);
}
} else {
logger.debug("redirect viewId=[{0}]", viewIdAndQueryString);
}
}
} else {
logger.debug("javax.portlet.faces.viewId=[{0}]", viewIdAndQueryString);
}
}
if ((viewIdAndQueryString != null) && !viewIdAndQueryString.startsWith("/")) {
viewIdAndQueryString = "/" + viewIdAndQueryString;
}
return viewIdAndQueryString;
}
Aggregations