use of javax.portlet.faces.Bridge 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.Bridge in project liferay-faces-bridge-impl by liferay.
the class ScopeCommonTests method scopeAfterRedisplayResourcePPRTest.
// Test is MultiRequest -- Render/Action
// Test # -- 5.66
@BridgeTest(test = "scopeAfterRedisplayResourcePPRTest")
public String scopeAfterRedisplayResourcePPRTest(TestBean testBean) {
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
Map<String, Object> requestMap = externalContext.getRequestMap();
Bridge.PortletPhase portletRequestPhase = BridgeUtil.getPortletRequestPhase(facesContext);
// parameter is true.
if (portletRequestPhase == Bridge.PortletPhase.RESOURCE_PHASE) {
requestMap.put("testAttr", testBean.getTestName());
return "";
} else // Otherwise, if this method is reached in the HEADER_PHASE of the portlet lifecycle, then
if (Bridge.PortletPhase.HEADER_PHASE.equals(portletRequestPhase)) {
String bridgeRequestScopeAjaxEnabledParam = externalContext.getInitParameter(Bridge.BRIDGE_REQUEST_SCOPE_AJAX_ENABLED);
boolean bridgeRequestScopeAjaxEnabled = "true".equalsIgnoreCase(bridgeRequestScopeAjaxEnabledParam);
// a re-render of the page which was invoked by a RenderURL.
if (externalContext.getRequestParameterMap().get("org.apache.portlet.faces.tck.redisplay") != null) {
testBean.setTestComplete(true);
// the portlet lifecycle when the "Run Test" button was clicked.
if (requestMap.get("com.liferay.faces.bridge.tck.pprSubmitted") != null) {
requestMap.remove("com.liferay.faces.bridge.tck.pprSubmitted");
// If the "pprSubmitted" request attribute has the expected value, then that means that this test
// method was properly called during the RESOURCE_PHASE of the portlet lifecycle.
Object testAttr = requestMap.get("testAttr");
if ((testAttr != null) && testAttr.equals(testBean.getTestName())) {
// If the bridge request scope is supposed to include Ajax requests, then the test has passed.
if (bridgeRequestScopeAjaxEnabled) {
testBean.setTestResult(true, "Redisplay after resource request CORRECTLY restored scoped attr that was added " + "during resource execution since the bridge request scope is supposed to include " + "Ajax requests.");
return Constants.TEST_SUCCESS;
} else // Otherwise, since the bridge request scope is not supposed to include Ajax requests, then
// the test has failed.
{
testBean.setTestResult(false, "Redisplay after resource request INCORRECTLY restored scoped attr that was added " + "during resource execution since the bridge request scope is not supposed to include " + "Ajax requests. NOTE: MAKE SURE YOU USED A NEW BROWSER TAB!");
return Constants.TEST_FAILED;
}
} else // Otherwise, the test has failed since the "pprSubmitted" request attribute does not have the
// expected value.
{
testBean.setTestResult(false, "Redisplay after resource request didn't restore the scoped attr that was added during " + "resource execution. NOTE: MAKE SURE YOU USED A NEW BROWSER TAB!");
return Constants.TEST_FAILED;
}
} else // Otherwise, since the "pprSubmitted" request attribute is not present, then
{
// portlet lifecycle into the RENDER_PHASE.
if (bridgeRequestScopeAjaxEnabled) {
testBean.setTestResult(false, "Redisplay after resource request INCORRECTLY did not restore the scoped attr that was " + "added during resource execution since the bridge request scope is supposed to include " + "Ajax requests. NOTE: MAKE SURE YOU USED A NEW BROWSER TAB!");
return Constants.TEST_FAILED;
} else // Otherwise, since the bridge request scope is not supposed to include Ajax requests, then the test
// is successful because the "pprSubmitted" attribute should not be preserved from the
// RESOURCE_PHASE of the portlet lifecycle into the RENDER_PHASE.
{
testBean.setTestResult(true, "Redisplay after resource request CORRECTLY did not restore the scoped attr that was added during " + "resource execution since the bridge request scope is not supposed to include Ajax requests.");
return Constants.TEST_SUCCESS;
}
}
}
}
// Otherwise -- no output
return "";
}
use of javax.portlet.faces.Bridge in project liferay-faces-bridge-impl by liferay.
the class ManualBridgeInvokePortlet method renderView.
@Override
public void renderView(RenderRequest renderRequest, MimeResponse mimeResponse) throws PortletException, IOException {
if (getTestName().equals(EXCEPTIONTHROWN_NODEFAULTVIEWID_TEST)) {
Bridge bridge = super.getFacesBridge(renderRequest, mimeResponse);
try {
doBridgeFacesRequest(bridge, renderRequest, mimeResponse);
} catch (BridgeDefaultViewNotSpecifiedException e) {
outputTestResult(renderRequest, mimeResponse, Boolean.TRUE, "Correctly threw BridgeDefaultViewNotSpecifiedException when no default defined.");
} catch (Exception e) {
outputTestResult(renderRequest, mimeResponse, Boolean.FALSE, "Didn't throw BridgeDefaultViewNotSpecifiedException when no default defined.");
}
} else if (getTestName().equals(BRIDGESETSCONTENTTYPE_TEST)) {
// Invoke the bridge directly and do not set the contentType (as is normally done in the outputTestResult
// method below). See the comments in bridgeSetsContentTypeTest for more information as to how the test
// is designed.
Bridge bridge = super.getFacesBridge(renderRequest, mimeResponse);
doBridgeFacesRequest(bridge, renderRequest, mimeResponse);
} else if (getTestName().equals(VIEWIDWITHPARAM_TEST)) {
renderRequest.setAttribute(Bridge.VIEW_ID, "/tests/singleRequestTest.xhtml?param1=testValue");
dispatchToView(renderRequest, mimeResponse);
} else if (getTestName().equals(FACESCONTEXTRELEASED_ACTION_TEST) || getTestName().equals(PORTLETPHASEREMOVED_ACTION_TEST) || getTestName().equals(FACESCONTEXTRELEASED_EVENT_TEST) || getTestName().equals(PORTLETPHASEREMOVED_EVENT_TEST)) {
// Output in the Test method fort his test
dispatchToView(renderRequest, mimeResponse);
} else if (getTestName().equals(FACESCONTEXTRELEASED_RENDER_TEST)) {
dispatchToView(renderRequest, mimeResponse);
if (renderRequest.getPortletSession(true).getAttribute("org.apache.portlet.faces.tck.facesContextReleased") != null) {
outputTestResult(renderRequest, mimeResponse, Boolean.TRUE, "Correctly release FacesContext at end of render.");
renderRequest.getPortletSession().removeAttribute("org.apache.portlet.faces.tck.facesContextReleased");
} else {
outputTestResult(renderRequest, mimeResponse, Boolean.FALSE, "FacesContext not release at end of render.");
}
} else if (getTestName().equals(PORTLETPHASEREMOVED_RENDER_TEST)) {
dispatchToView(renderRequest, mimeResponse);
if (renderRequest.getAttribute(Bridge.PORTLET_LIFECYCLE_PHASE) == null) {
outputTestResult(renderRequest, mimeResponse, Boolean.TRUE, "Correctly removed Portlet Phase attribute at end of render.");
} else {
outputTestResult(renderRequest, mimeResponse, Boolean.FALSE, "Didn't remove Portlet Phase attribute at end of render.");
}
} else {
dispatchToView(renderRequest, mimeResponse);
}
}
use of javax.portlet.faces.Bridge in project liferay-faces-bridge-impl by liferay.
the class EncodeActionURLResourceTests method encodeActionURLJSFViewResourceTest.
// Test Resource followed by Action + Render
// Test #6.111
@BridgeTest(test = "encodeActionURLJSFViewResourceTest")
public String encodeActionURLJSFViewResourceTest(TestBean testBean) {
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
Map<String, String> requestParameterMap = externalContext.getRequestParameterMap();
Bridge.PortletPhase portletRequestPhase = BridgeUtil.getPortletRequestPhase(facesContext);
// button will be a full page (rather than an Ajax) postback.
if (portletRequestPhase == Bridge.PortletPhase.RESOURCE_PHASE) {
FacesMessage facesMessage = new FacesMessage("Ajax postback executed. Click link to run a subsequent full page postback.");
facesContext.addMessage(null, facesMessage);
ViewBean viewBean = getViewBean(facesContext);
viewBean.setAjaxEnabled(false);
return "";
} else // form's "action" attribute).
if (portletRequestPhase == Bridge.PortletPhase.ACTION_PHASE) {
// Here in the ACTION_PHASE, return an action outcome that will cause the FacesBridge navigation-handler to
// execute a navigation-rule in order to navigate to a different view (in the ACTION_PHASE) by:
//
// 1) Creating an action BridgeURL that encodes target viewId=multiRequestTestResultRenderCheck.xhtml (in
// the RI, see the BridgeNavigationHandlerImpl.handleNavigation(FacesContext,String,String) method).
//
// 2) Extracting portlet mode, window state, and render parameters (a.k.a. Portlet 3.0 "render state") from
// the action BridgeURL and setting them on the StateAwareResponse (in the RI, see the
// BridgeNavigationUtil.navigate(PortletRequest,StateAwareResponse,Map<String,String[]> method).
//
// Note that the client window id "jsfwid" parameter is encoded on the actionURL in #1 and set as a render
// parameter in #2 so that it will be picked up in the HEADER_PHASE.
ActionResponse actionResponse = (ActionResponse) externalContext.getResponse();
String actionClientWindowId = requestParameterMap.get(ResponseStateManager.CLIENT_WINDOW_URL_PARAM);
if (actionClientWindowId != null) {
actionResponse.setRenderParameter("actionClientWindowId", actionClientWindowId);
}
// action Navigation result
return "encodeActionURLJSFViewResourceTest";
} else // Otherwise, if this method is reached in the HEADER_PHASE of the portlet lifecycle then the bridge executed a
// navigation-rule to viewId=multiRequestTestResultRenderCheck.xhtml in order to display the test results. This
// verifies that the action BridgeURL created in the ACTION_PHASE correctly encoded the viewId (and if client
// window mode is enabled, the "jsfwid" parameter as well).
{
String actionClientWindowId = requestParameterMap.get("actionClientWindowId");
String renderClientWindowId = requestParameterMap.get(ResponseStateManager.CLIENT_WINDOW_URL_PARAM);
if (ClientWindowTestUtil.isClientWindowEnabled(externalContext)) {
String clientWindowId = ClientWindowTestUtil.getClientWindowId(externalContext);
if ((actionClientWindowId != null) && (actionClientWindowId.length() > 0)) {
if (actionClientWindowId.equals(clientWindowId)) {
if (actionClientWindowId.equals(renderClientWindowId)) {
testBean.setTestResult(true, "encodeActionURL correctly encoded the viewId in the RESOURCE_PHASE of the portlet " + "lifecycle and the " + ResponseStateManager.CLIENT_WINDOW_URL_PARAM + " request parameter value=[" + actionClientWindowId + "] is equal to ClientWindow.getId().");
} else {
testBean.setTestResult(true, "The " + ResponseStateManager.CLIENT_WINDOW_URL_PARAM + " RENDER parameter value=[" + renderClientWindowId + "] is NOT equal to the ACTION parameter value=[" + actionClientWindowId + "]. This can indicate one of two problems: 1) encodeActionURL " + " did not encode " + ResponseStateManager.CLIENT_WINDOW_URL_PARAM + " in the " + "ACTION_PHASE or the navigation handler did not set the " + ResponseStateManager.CLIENT_WINDOW_URL_PARAM + " RENDER parameter in the ACTION_PHASE.");
}
} else {
testBean.setTestResult(false, "encodeActionURL returned a URL such that the " + ResponseStateManager.CLIENT_WINDOW_URL_PARAM + " request parameter value=[" + actionClientWindowId + "] did NOT equal ClientWindow.getId()=[" + clientWindowId + "].");
}
} else {
testBean.setTestResult(false, "encodeActionURL returned a URL that contained a null value for the " + ResponseStateManager.CLIENT_WINDOW_URL_PARAM + " request parameter.");
}
} else {
if (renderClientWindowId != null) {
testBean.setTestResult(false, "Incorrectly found a non-null " + ResponseStateManager.CLIENT_WINDOW_URL_PARAM + " request parameter with value=[" + renderClientWindowId + "] in the " + portletRequestPhase + " even though the client window feature is disabled.");
} else if (actionClientWindowId != null) {
testBean.setTestResult(false, "encodeActionURL returned a URL that (when generated in the RESOURCE_PHASE) incorrectly " + "included the " + ResponseStateManager.CLIENT_WINDOW_URL_PARAM + " request parameter with value=[" + actionClientWindowId + "] even though the client window feature is disabled.");
} else {
testBean.setTestResult(true, "encodeActionURL correctly encoded the viewId in the RESOURCE_PHASE of the portlet lifecycle.");
}
}
testBean.setTestComplete(true);
if (testBean.getTestStatus()) {
return Constants.TEST_SUCCESS;
} else {
return Constants.TEST_FAILED;
}
}
}
use of javax.portlet.faces.Bridge in project liferay-faces-bridge-impl by liferay.
the class BridgeURLResourceImpl method toBaseURL.
@Override
public BaseURL toBaseURL(FacesContext facesContext) throws MalformedURLException {
BaseURL baseURL;
String uri = bridgeURI.toString();
// doesn't have the double-forward-slash like "http://" does, then
if (bridgeURI.isOpaque()) {
// parameters. This will be a URL that represents navigation to a different viewId.
if (bridgeURI.isPortletScheme()) {
// TCK: modeViewIDTest
// TCK: requestRenderIgnoresScopeViaCreateViewTest
// TCK: requestRenderRedisplayTest
// TCK: requestRedisplayOutOfScopeTest
// TCK: renderRedirectTest
// TCK: ignoreCurrentViewIdModeChangeTest
// TCK: exceptionThrownWhenNoDefaultViewIdTest
String portletMode = getParameter(Bridge.PORTLET_MODE_PARAMETER);
boolean modeChanged = ((portletMode != null) && (portletMode.length() > 0));
Bridge.PortletPhase urlPortletPhase = bridgeURI.getPortletPhase();
if (urlPortletPhase == Bridge.PortletPhase.ACTION_PHASE) {
baseURL = createActionURL(facesContext, modeChanged);
} else if (urlPortletPhase == Bridge.PortletPhase.RENDER_PHASE) {
baseURL = createRenderURL(facesContext, modeChanged);
} else {
baseURL = createResourceURL(facesContext, modeChanged);
}
// user clicks on the link (invokes the BaseURL).
if (selfReferencing) {
ExternalContext externalContext = facesContext.getExternalContext();
PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
copyRenderParameters(portletRequest, baseURL, externalContext.encodeNamespace(""), UINamingContainer.getSeparatorChar(facesContext));
}
// PortletURL.
if (baseURL instanceof PortletURL) {
PortletURL portletURL = (PortletURL) baseURL;
ExternalContext externalContext = facesContext.getExternalContext();
PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
PortletURLHelper.setPortletMode(portletURL, portletMode, portletRequest);
String windowState = getParameter(Bridge.PORTLET_WINDOWSTATE_PARAMETER);
PortletURLHelper.setWindowState(portletURL, windowState, portletRequest);
}
// Apply the security.
String secure = getParameter(Bridge.PORTLET_SECURE_PARAMETER);
PortletURLHelper.setSecure(baseURL, secure);
// According to the Bridge Spec, the "javax.portlet.faces.Secure" parameter must not be "carried
// forward to the generated reference." According to a clarification in the Portlet 3.0 JavaDoc for
// BaseURL#setProperty(String,String), setting the parameter to null will remove it.
baseURL.setParameter(Bridge.PORTLET_SECURE_PARAMETER, (String) null);
} else // Otherwise, return the a BaseURL string representation (unmodified value) as required by the Bridge Spec.
{
// TCK: encodeResourceURLOpaqueTest
baseURL = new BaseURLNonEncodedImpl(bridgeURI, encoding);
}
} else // Otherwise, if the URL is a JSF2 portlet resource URL, then
if (PortletResourceUtilCompat.isPortletResourceURL(uri)) {
// FACES-63 Return the URI unmodified to prevent double-encoding of resource URLs.
baseURL = new BaseURLBridgeURIAdapterImpl(bridgeURI);
} else // resource URL identifier, then return a ResourceURL that can retrieve the JSF2 resource.
if ((uri != null) && uri.contains("javax.faces.resource")) {
baseURL = createResourceURL(facesContext, bridgeURI.getParameterMap());
} else // of the URL that contains the context-path.
if (bridgeURI.isPathRelative()) {
// TCK: encodeResourceURLRelativeURLTest
// TCK: encodeResourceURLRelativeURLBackLinkTest
ExternalContext externalContext = facesContext.getExternalContext();
String contextPath = externalContext.getRequestContextPath();
baseURL = new BaseURLRelativeImpl(bridgeURI, contextPath);
} else // Otherwise, if the URL is external, then return an encoded BaseURL string representation of the URL.
if (bridgeURI.isExternal(contextPath)) {
// TCK: encodeResourceURLForeignExternalURLBackLinkTest
ExternalContext externalContext = facesContext.getExternalContext();
PortletResponse portletResponse = (PortletResponse) externalContext.getResponse();
baseURL = new BaseURLPortletResponseEncodedImpl(bridgeURI, portletResponse);
} else // to a different Faces view, then
if (viewLink) {
String portletMode = getParameter(Bridge.PORTLET_MODE_PARAMETER);
String windowState = getParameter(Bridge.PORTLET_WINDOWSTATE_PARAMETER);
boolean secure = BooleanHelper.toBoolean(getParameter(Bridge.PORTLET_SECURE_PARAMETER));
// JavaDoc comments for {@link Bridge#VIEW_LINK}.
if (getViewId() != null) {
// TCK: encodeResourceURLViewLinkTest
// TCK: encodeResourceURLViewLinkWithBackLinkTest
ExternalContext externalContext = facesContext.getExternalContext();
PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
PortletURL actionURL = createActionURL(facesContext, PortletURLHelper.EXCLUDED_PARAMETER_NAMES);
PortletURLHelper.setPortletMode(actionURL, portletMode, portletRequest);
PortletURLHelper.setWindowState(actionURL, windowState, portletRequest);
PortletURLHelper.setSecure(actionURL, secure);
// According to the Bridge Spec, the "javax.portlet.faces.Secure" parameter must not be "carried
// forward to the generated reference." According to a clarification in the Portlet 3.0 JavaDoc for
// BaseURL#setProperty(String,String), setting the parameter to null will remove it.
actionURL.setParameter(Bridge.PORTLET_SECURE_PARAMETER, (String) null);
baseURL = actionURL;
} else // Otherwise, return a PortletURL (Render URL) that contains the "_jsfBridgeNonFacesView" render parameter,
// which is a signal to the GenericFacesPortlet to dispatch to this non-Faces target when the URL is
// requested. Note that this seems to be a use-case that is contradictory with the JavaDoc for
// Brige#VIEW_LINK which claims navigation to a different view. But there are a number of tests in the TCK
// that utilize this (see below).
{
Bridge.PortletPhase portletRequestPhase = BridgeUtil.getPortletRequestPhase(facesContext);
if (isHeaderOrRenderOrResourcePhase(portletRequestPhase)) {
// TCK: encodeActionURLNonJSFViewRenderTest
// TCK: encodeActionURLNonJSFViewWithParamRenderTest
// TCK: encodeActionURLNonJSFViewWithModeRenderTest
// TCK: encodeActionURLNonJSFViewWithInvalidModeRenderTest
// TCK: encodeActionURLNonJSFViewWithWindowStateRenderTest
// TCK: encodeActionURLNonJSFViewWithInvalidWindowStateRenderTest
// TCK: encodeActionURLNonJSFViewResourceTest
// TCK: encodeActionURLNonJSFViewWithParamResourceTest
// TCK: encodeActionURLNonJSFViewWithModeResourceTest
// TCK: encodeActionURLNonJSFViewWithInvalidModeResourceTest
// TCK: encodeActionURLNonJSFViewWithWindowStateResourceTest
// TCK: encodeActionURLNonJSFViewWithInvalidWindowStateResourceTest
ExternalContext externalContext = facesContext.getExternalContext();
PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
PortletURL renderURL = createRenderURL(facesContext, PortletURLHelper.EXCLUDED_PARAMETER_NAMES);
renderURL.setParameter(Bridge.NONFACES_TARGET_PATH_PARAMETER, bridgeURI.getPath());
PortletURLHelper.setPortletMode(renderURL, portletMode, portletRequest);
PortletURLHelper.setWindowState(renderURL, windowState, portletRequest);
PortletURLHelper.setSecure(renderURL, secure);
// According to the Bridge Spec, the "javax.portlet.faces.Secure" parameter must not be "carried
// forward to the generated reference." According to a clarification in the Portlet 3.0 JavaDoc for
// BaseURL#setProperty(String,String), setting the parameter to null will remove it.
renderURL.setParameter(Bridge.PORTLET_SECURE_PARAMETER, (String) null);
baseURL = renderURL;
} else {
throw new IllegalStateException("Unable to encode a URL for a non-Faces view in the " + portletRequestPhase + " of the portlet lifecycle.");
}
}
} else // Otherwise, if the URL targets a Faces viewId, then return a ResourceURL that targets the view.
if (getViewId() != null) {
// TCK: resourceAttrRetainedAfterRedisplayPPRTest
// TCK: encodeActionURLJSFViewResourceTest
// TCK: encodeActionURLWithParamResourceTest
// TCK: encodeActionURLWithModeResourceTest
// TCK: encodeActionURLWithInvalidModeResourceTest
// TCK: encodeActionURLWithWindowStateResourceTest
// TCK: encodeActionURLWithInvalidWindowStateResourceTest
// TCK: encodeURLEscapingTest
// TCK: encodeResourceURLWithModeTest
baseURL = createResourceURL(facesContext, PortletURLHelper.EXCLUDED_PARAMETER_NAMES);
} else // an appropriate ResourceURL.
if (inProtocol) {
// TCK: nonFacesResourceTest
ResourceURL resourceURL = createResourceURL(facesContext);
resourceURL.setResourceID(bridgeURI.getContextRelativePath(contextPath));
baseURL = resourceURL;
} else // Otherwise, assume that the URL is for an resource external to the portlet context like
// "/portalcontext/resources/foo.png" and return a BaseURL string representation of it.
{
// TCK: encodeResourceURLTest
// TCK: encodeResourceURLBackLinkTest
baseURL = new BaseURLBridgeURIAdapterImpl(bridgeURI);
}
return baseURL;
}
Aggregations