use of com.liferay.faces.bridge.tck.beans.ViewBean in project liferay-faces-bridge-impl by liferay.
the class EncodeActionURLResourceTests method getViewBean.
private ViewBean getViewBean(FacesContext facesContext) {
Application application = facesContext.getApplication();
ELResolver elResolver = application.getELResolver();
ELContext elContext = facesContext.getELContext();
return (ViewBean) elResolver.getValue(elContext, null, "viewBean");
}
use of com.liferay.faces.bridge.tck.beans.ViewBean 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;
}
}
}
Aggregations