use of javax.portlet.faces.event.EventNavigationResult in project liferay-faces-bridge-impl by liferay.
the class BridgePhaseEventImpl method execute.
// Java 1.6+ @Override
@Override
public void execute() throws BridgeDefaultViewNotSpecifiedException, BridgeException {
logger.debug(Logger.SEPARATOR);
logger.debug("execute(EventRequest, EventResponse) portletName=[{0}]", portletName);
String bridgeEventHandlerAttributeName = Bridge.BRIDGE_PACKAGE_PREFIX + portletName + "." + Bridge.BRIDGE_EVENT_HANDLER;
BridgeEventHandler bridgeEventHandler = (BridgeEventHandler) portletContext.getAttribute(bridgeEventHandlerAttributeName);
if (bridgeEventHandler == null) {
bridgeEventHandler = BridgeEventHandlerFactory.getBridgeEventHandlerInstance(portletConfig);
}
try {
// If there is a bridgeEventHandler registered in portlet.xml, then
if (bridgeEventHandler != null) {
init(eventRequest, eventResponse, Bridge.PortletPhase.EVENT_PHASE);
// Restore the BridgeRequestScope that may have started during the ACTION_PHASE.
bridgeRequestScope.restoreState(facesContext);
// PROPOSED-FOR-BRIDGE3-API: https://issues.apache.org/jira/browse/PORTLETBRIDGE-202
bridgeRequestScope.setPortletMode(eventRequest.getPortletMode());
// Execute the JSF lifecycle so that ONLY the RESTORE_VIEW phase executes (note that this this is
// accomplished by the IPCPhaseListener).
facesLifecycle.execute(facesContext);
throwQueuedExceptionIfNecessary(facesContext);
// Set a flag on the bridge request scope indicating that the Faces Lifecycle has executed.
bridgeRequestScope.setFacesLifecycleExecuted(true);
// If there is a bridgeEventHandler registered in portlet.xml, then invoke the handler so that it
// can process the event payload.
logger.debug("Invoking {0} for class=[{1}]", bridgeEventHandlerAttributeName, bridgeEventHandler.getClass());
Event event = eventRequest.getEvent();
EventNavigationResult eventNavigationResult = bridgeEventHandler.handleEvent(facesContext, event);
if (eventNavigationResult != null) {
String oldViewId = facesContext.getViewRoot().getViewId();
String fromAction = eventNavigationResult.getFromAction();
String outcome = eventNavigationResult.getOutcome();
logger.debug("Invoking navigationHandler fromAction=[{0}] outcome=[{1}]", fromAction, outcome);
NavigationHandler navigationHandler = facesContext.getApplication().getNavigationHandler();
navigationHandler.handleNavigation(facesContext, fromAction, outcome);
String newViewId = facesContext.getViewRoot().getViewId();
bridgeRequestScope.setNavigationOccurred(!oldViewId.equals(newViewId));
}
// Process the outgoing public render parameters.
// TCK (eventControllerTest)
processOutgoingPublicRenderParameters(facesLifecycle);
// Save the faces view root and any messages in the faces context so that they can be restored during
// the RENDER_PHASE of the portlet lifecycle.
bridgeRequestScope.saveState(facesContext);
// In accordance with Section 5.2.5 of the Spec, if a portlet mode change has occurred, then the
// bridge request scope must not be maintained.
//
// NOTE: THIS REQUIREMENT IS HANDLED BY THE RENDER PHASE since the current design relies on
// BridgeRequestScope.restoreState(FacesContext) to detect portlet mode changes in some cases.
//
// PROPOSE-FOR-BRIDGE3-SPEC: Although the spec does not mention the redirect case, the bridge request
// scope must not be maintained if a redirect has occurred.
//
// REDIRECT:
// ---------
// TCK (eventScopeNotRestoredRedirectTest)
// TCK (redirectEventTest)
//
// PORTLET MODE CHANGED:
// ---------------------
// TCK (eventScopeNotRestoredModeChangedTest)
// TCK (encodeActionURLWithModeEventTest)
//
// NON-REDIRECT / SAME PORTLET MODE:
// ---------------------------------
// TCK (eventPhaseListenerTest)
// TCK (eventScopeRestoredTest)
// TCK (eventControllerTest)
// TCK (encodeActionURLJSFViewEventTest)
// TCK (encodeActionURLWithParamEventTest)
// TCK (encodeActionURLWithInvalidModeEventTest),
// TCK (encodeActionURLWithWindowStateEventTest)
// TCK (encodeActionURLWithInvalidWindowStateEventTest)
// TCK (getRequestHeaderMapEventTest)
// TCK (getRequestHeaderValuesMapEventTest)
// TCK (getRequestCharacterEncodingEventTest)
// TCK (getRequestContentTypeEventTest)
// TCK (getResponseCharacterEncodingEventTest)
// TCK (getResponseContentTypeEventTest)
// Assume that the bridge request scope should be maintained from the EVENT_PHASE into the
// RENDER_PHASE by utilizing render parameters.
BridgeRequestScope.Transport bridgeRequestScopeTransport = BridgeRequestScope.Transport.RENDER_PARAMETER;
Serializable eventPayload = event.getValue();
// redirect.
if ((eventPayload != null) && (eventPayload instanceof EventPayloadWrapper)) {
EventPayloadWrapper eventPayloadWrapper = (EventPayloadWrapper) eventPayload;
if (eventPayloadWrapper.isRedirect()) {
bridgeRequestScopeTransport = BridgeRequestScope.Transport.PORTLET_SESSION_ATTRIBUTE;
}
}
maintainBridgeRequestScope(eventRequest, eventResponse, bridgeRequestScopeTransport);
}
// Maintain the render parameters set in the ACTION_PHASE so that they carry over to the RENDER_PHASE.
maintainRenderParameters(eventRequest, eventResponse);
// Spec 6.6 (Namespacing)
if (bridgeEventHandler != null) {
indicateNamespacingToConsumers(facesContext.getViewRoot(), eventResponse);
}
} catch (Throwable t) {
throw new BridgeException(t);
} finally {
if (bridgeEventHandler != null) {
cleanup(eventRequest);
}
}
}
use of javax.portlet.faces.event.EventNavigationResult in project liferay-faces-bridge-impl by liferay.
the class CustomerSelectedEventHandler method handleEvent.
public EventNavigationResult handleEvent(FacesContext facesContext, Event event) {
EventNavigationResult eventNavigationResult = null;
String eventQName = event.getQName().toString();
if (eventQName.equals("{http://liferay.com/events}ipc.customerSelected")) {
Serializable value = event.getValue();
// payload from the wrapper.
if (value instanceof EventPayloadWrapper) {
value = ((EventPayloadWrapper) value).getWrapped();
}
Customer customer = (Customer) value;
BookingsModelBean bookingsModelBean = getBookingsModelBean(facesContext);
bookingsModelBean.setCustomer(customer);
String fromAction = null;
String outcome = "ipc.customerSelected";
eventNavigationResult = new EventNavigationResult(fromAction, outcome);
logger.debug("Received event ipc.customerSelected for customerId=[{0}] firstName=[{1}] lastName=[{2}]", new Object[] { customer.getCustomerId(), customer.getFirstName(), customer.getLastName() });
}
return eventNavigationResult;
}
use of javax.portlet.faces.event.EventNavigationResult in project liferay-faces-bridge-impl by liferay.
the class CustomerEditedEventHandler method handleEvent.
public EventNavigationResult handleEvent(FacesContext facesContext, Event event) {
EventNavigationResult eventNavigationResult = null;
String eventQName = event.getQName().toString();
if (eventQName.equals("{http://liferay.com/events}ipc.customerEdited")) {
Customer customer = (Customer) event.getValue();
getCustomerService(facesContext).save(customer);
logger.debug("Received event ipc.customerEdited for customerId=[{0}] firstName=[{1}] lastName=[{2}]", new Object[] { customer.getCustomerId(), customer.getFirstName(), customer.getLastName() });
}
return eventNavigationResult;
}
use of javax.portlet.faces.event.EventNavigationResult in project liferay-faces-bridge-impl by liferay.
the class Ch5TestEventHandler method handleEvent.
@Override
public EventNavigationResult handleEvent(FacesContext facesContext, Event event) {
Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap();
Map<String, Object> sessionMap = facesContext.getExternalContext().getSessionMap();
String testName = (String) event.getValue();
String portletTestName = (String) requestMap.get(Constants.TEST_NAME);
if (testName == null) {
requestMap.put(EVENT_TEST_FAILED, "Event test failed because the payload is null instead of being the name of the test this event pertains to.");
}
if ((testName == null) || (portletTestName == null) || !testName.equals(portletTestName)) {
// test and ignore for all the other tests/portlets
return null;
}
sessionMap.put(EVENT_RECEIVED, event);
if (testName.equals("eventScopeRestoredTest")) {
// test -- that the request attr set in action is restored
String payload = (String) requestMap.get("portlet.bridge.tck.testAttr");
if ((payload == null) || !payload.equals(testName)) {
sessionMap.put(EVENT_TEST_FAILED, "Event received but request scope wasn't restored.");
return null;
}
return null;
} else if (testName.equals("eventScopeNotRestoredRedirectTest")) {
// test -- that the request attr set in action is restored
String payload = (String) requestMap.get("portlet.bridge.tck.testAttr");
if ((payload == null) || !payload.equals(testName)) {
sessionMap.put(EVENT_TEST_FAILED, "Event received but request scope wasn't restored.");
}
return new EventNavigationResult(null, testName + "EventNavigation");
} else if (testName.equals("eventScopeNotRestoredModeChangedTest")) {
// test -- that the request attr set in action is restored
String payload = (String) requestMap.get("portlet.bridge.tck.testAttr");
if ((payload == null) || !payload.equals(testName)) {
sessionMap.put(EVENT_TEST_FAILED, "Event received but request scope wasn't restored.");
}
return new EventNavigationResult(null, testName + "EventNavigation");
} else if (testName.equals("eventControllerTest")) {
// Verify the event phase attribute is set
Bridge.PortletPhase phase = (Bridge.PortletPhase) requestMap.get(Bridge.PORTLET_LIFECYCLE_PHASE);
requestMap.put("tck.eventPhaseCheck", new Boolean((phase != null) && (phase == Bridge.PortletPhase.EVENT_PHASE)));
// Now verify that a change to a public render parameter is carried forward
String currentValue = (String) requestMap.get("modelPRP");
if (currentValue == null) {
currentValue = "1";
} else {
currentValue = currentValue.concat("1");
}
// Config is setup to exclude this value from bridge request scope -- so only get carried forward
// if received in render request
requestMap.put("modelPRP", currentValue);
// Stash copy of value in an attr that is carried forward to compare.
requestMap.put("tck.compareModelPRPValue", currentValue);
// Verify that event navigation works
return new EventNavigationResult(null, testName + "EventNavigation");
}
return null;
}
Aggregations