use of javax.portlet.StateAwareResponse in project liferay-faces-bridge-impl by liferay.
the class Tests method eventNoHandlerPRPPreservedTest.
// Test is MultiRequest -- Render/Action
// Test # -- 5.58
@BridgeTest(test = "eventNoHandlerPRPPreservedTest")
public String eventNoHandlerPRPPreservedTest(TestBean testBean) {
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
// are explicitly excluded -- test for presence/absence in render
if (BridgeUtil.getPortletRequestPhase(facesContext) == Bridge.PortletPhase.ACTION_PHASE) {
// Set the value into the model underneath the public render parameter
externalContext.getRequestMap().put("modelPRP", testBean.getTestName());
// Create and raise the event
StateAwareResponse stateAwareResponse = (StateAwareResponse) externalContext.getResponse();
stateAwareResponse.setEvent(new QName(Constants.EVENT_QNAME, Constants.EVENT_NAME), testBean.getTestName());
// action Navigation result
return "eventNoHandlerPRPPreservedTest";
} else {
testBean.setTestComplete(true);
// ensure that both the public render paramter and the model are there and have the same value
RenderRequest request = (RenderRequest) externalContext.getRequest();
String[] prpArray = request.getPublicParameterMap().get("testPRP");
String modelPRP = (String) externalContext.getRequestMap().get("modelPRP");
if (prpArray == null) {
testBean.setTestResult(false, "event raised without a registered handler didn't carry forward the public render parameter.");
return Constants.TEST_FAILED;
} else if (modelPRP == null) {
testBean.setTestResult(false, "event raised without a registered handler didn't update the model from the passed public render parameter.");
return Constants.TEST_FAILED;
} else if (!modelPRP.equals(prpArray[0])) {
testBean.setTestResult(false, "event raised without a registered handler: passed public render parameter value doesn't match underlying one.");
return Constants.TEST_FAILED;
} else if (!modelPRP.equals(testBean.getTestName())) {
testBean.setTestResult(false, "event raised without a registered handler: public render parameter didn't contain expected value. PRP value: " + modelPRP + " but expected: " + testBean.getTestName());
return Constants.TEST_FAILED;
} else {
testBean.setTestResult(true, "event raised without a registered handler worked correctly as the public render parameter was maintained.");
return Constants.TEST_SUCCESS;
}
}
}
use of javax.portlet.StateAwareResponse in project liferay-faces-bridge-impl by liferay.
the class Tests method eventScopeNotRestoredRedirectTest.
// Test is MultiRequest -- Render/Action
// Test # -- 5.49
@BridgeTest(test = "eventScopeNotRestoredRedirectTest")
public String eventScopeNotRestoredRedirectTest(TestBean testBean) {
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
// are explicitly excluded -- test for presence/absence in render
if (BridgeUtil.getPortletRequestPhase(facesContext) == Bridge.PortletPhase.ACTION_PHASE) {
// Clear settings from previous run of the test
externalContext.getSessionMap().put(Ch5TestEventHandler.EVENT_RECEIVED, null);
externalContext.getSessionMap().put(Ch5TestEventHandler.EVENT_TEST_FAILED, null);
// Place a request attr in scope so we can make sure its not there later
externalContext.getRequestMap().put(Ch5TestEventHandler.EVENTATTR, testBean.getTestName());
// Create and raise the event
StateAwareResponse stateAwareResponse = (StateAwareResponse) externalContext.getResponse();
stateAwareResponse.setEvent(new QName(Constants.EVENT_QNAME, Constants.EVENT_NAME), testBean.getTestName());
// action Navigation result
return "eventScopeNotRestoredRedirectTest";
} else {
testBean.setTestComplete(true);
// Values set by portlet at end of action
Event event = (Event) externalContext.getSessionMap().get(Ch5TestEventHandler.EVENT_RECEIVED);
String failedMsg = (String) externalContext.getSessionMap().get(Ch5TestEventHandler.EVENT_TEST_FAILED);
String payload = (String) externalContext.getRequestMap().get(Ch5TestEventHandler.EVENTATTR);
if (event == null) {
testBean.setTestResult(false, "Raised event wasn't received.");
return Constants.TEST_FAILED;
} else if (failedMsg != null) {
testBean.setTestResult(false, failedMsg);
return Constants.TEST_FAILED;
} else if (payload != null) {
testBean.setTestResult(false, "Event navigation issued a redirect but the request scope was preserved.");
return Constants.TEST_FAILED;
} else {
testBean.setTestResult(true, "Request scope not preserved after event navigation issued a redirect.");
return Constants.TEST_SUCCESS;
}
}
}
use of javax.portlet.StateAwareResponse in project liferay-faces-bridge-impl by liferay.
the class Tests method eventScopeRestoredTest.
// Test is MultiRequest -- Render/Action
// Test # -- 5.48
@BridgeTest(test = "eventScopeRestoredTest")
public String eventScopeRestoredTest(TestBean testBean) {
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
// are explicitly excluded -- test for presence/absence in render
if (BridgeUtil.getPortletRequestPhase(facesContext) == Bridge.PortletPhase.ACTION_PHASE) {
// Clear settings from previous run of the test: Done here because this render doesn't happen in scope so
// second rendition doesn't keep the test result -- rather rerenders
externalContext.getSessionMap().put(Ch5TestEventHandler.EVENT_RECEIVED, null);
externalContext.getSessionMap().put(Ch5TestEventHandler.EVENT_TEST_FAILED, null);
// Place a request attr in scope so we can make sure its still there later
externalContext.getRequestMap().put(Ch5TestEventHandler.EVENTATTR, testBean.getTestName());
// Create and raise the event
StateAwareResponse stateAwareResponse = (StateAwareResponse) externalContext.getResponse();
stateAwareResponse.setEvent(new QName(Constants.EVENT_QNAME, Constants.EVENT_NAME), testBean.getTestName());
// action Navigation result
return "eventScopeRestoredTest";
} else {
testBean.setTestComplete(true);
// Values set by portlet at end of action
Event event = (Event) externalContext.getSessionMap().get(Ch5TestEventHandler.EVENT_RECEIVED);
String failedMsg = (String) externalContext.getSessionMap().get(Ch5TestEventHandler.EVENT_TEST_FAILED);
String payload = (String) externalContext.getRequestMap().get(Ch5TestEventHandler.EVENTATTR);
if (event == null) {
testBean.setTestResult(false, "Raised event wasn't received.");
return Constants.TEST_FAILED;
} else if (failedMsg != null) {
testBean.setTestResult(false, failedMsg);
return Constants.TEST_FAILED;
} else if ((payload == null) || !payload.equals(testBean.getTestName())) {
testBean.setTestResult(false, "Event received and request scope restored but that scope wasn't carried forward into the render");
return Constants.TEST_FAILED;
} else {
testBean.setTestResult(true, "Event received and request scope restored.");
return Constants.TEST_SUCCESS;
}
}
}
use of javax.portlet.StateAwareResponse in project liferay-faces-bridge-impl by liferay.
the class Tests method portletPhaseRemovedEventTest.
// Test is MultiRequest -- Render/Action
// Test #5.60
@BridgeTest(test = "portletPhaseRemovedEventTest")
public String portletPhaseRemovedEventTest(TestBean testBean) {
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
// are explicitly excluded -- test for presence/absence in render
if (BridgeUtil.getPortletRequestPhase(facesContext) == Bridge.PortletPhase.ACTION_PHASE) {
StateAwareResponse stateAwareResponse = (StateAwareResponse) externalContext.getResponse();
stateAwareResponse.setEvent(new QName(Constants.EVENT_QNAME, Constants.EVENT_NAME), testBean.getTestName());
// action Navigation result
return "portletPhaseRemovedEventTest";
} else {
testBean.setTestComplete(true);
// Values set by portlet at end of action
boolean result = ((Boolean) externalContext.getSessionMap().get("org.apache.portlet.faces.tck.testResult")).booleanValue();
testBean.setTestResult(result, (String) externalContext.getSessionMap().get("org.apache.portlet.faces.tck.testDetail"));
if (result) {
return Constants.TEST_SUCCESS;
} else {
return Constants.TEST_FAILED;
}
}
}
use of javax.portlet.StateAwareResponse in project liferay-faces-bridge-impl by liferay.
the class BridgeNavigationHandlerImpl method handleNavigation.
@Override
public void handleNavigation(FacesContext facesContext, String fromAction, String outcome) {
logger.debug("fromAction=[{0}] outcome=[{1}]", fromAction, outcome);
String queryString = null;
UIViewRoot uiViewRoot = facesContext.getViewRoot();
String viewId = uiViewRoot.getViewId();
if (viewId != null) {
int pos = viewId.indexOf("?");
if (pos > 0) {
queryString = viewId.substring(pos);
viewId = viewId.substring(0, pos);
uiViewRoot.setViewId(viewId);
}
}
NavigationCase navigationCase = getNavigationCase(facesContext, fromAction, outcome);
// Ask the wrapped NavigationHandler to perform the navigation.
getWrappedNavigationHandler().handleNavigation(facesContext, fromAction, outcome);
if (queryString != null) {
uiViewRoot.setViewId(viewId.concat(queryString));
}
if (navigationCase != null) {
// Hack for http://jira.icesoft.org/browse/ICE-7996
Iterator<FacesMessage> itr = facesContext.getMessages();
while (itr.hasNext()) {
FacesMessage facesMessage = itr.next();
if (facesMessage.getDetail().contains("Unable to find matching navigation case")) {
logger.warn("Removed bogus FacesMessage caused by http://jira.icesoft.org/browse/ICE-7996");
itr.remove();
}
}
// ExternalContext.redirect(String) directly from their application.
if (!navigationCase.isRedirect()) {
String toViewId = navigationCase.getToViewId(facesContext);
if (toViewId != null) {
ExternalContext externalContext = facesContext.getExternalContext();
PortletResponse portletResponse = (PortletResponse) externalContext.getResponse();
if (portletResponse instanceof StateAwareResponse) {
PortletContext portletContext = (PortletContext) externalContext.getContext();
BridgeURLFactory bridgeURLFactory = (BridgeURLFactory) BridgeFactoryFinder.getFactory(portletContext, BridgeURLFactory.class);
try {
BridgeURL bridgeActionURL = bridgeURLFactory.getBridgeActionURL(facesContext, toViewId);
BridgeNavigationCase bridgeNavigationCase = new BridgeNavigationCaseImpl(navigationCase);
String portletMode = bridgeNavigationCase.getPortletMode();
if (portletMode != null) {
bridgeActionURL.setParameter(Bridge.PORTLET_MODE_PARAMETER, portletMode);
}
String windowState = bridgeNavigationCase.getWindowState();
if (windowState != null) {
bridgeActionURL.setParameter(Bridge.PORTLET_WINDOWSTATE_PARAMETER, windowState);
}
PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
BridgeNavigationUtil.navigate(portletRequest, (StateAwareResponse) portletResponse, bridgeActionURL.getParameterMap());
} catch (Exception e) {
logger.error(e.getMessage());
}
}
}
}
}
}
Aggregations