HttpServletRequest request = req.getRequestObject();
ControllerStatus controllerStatus = ControllerStatus.lookup();
// Check whether the modal window has been activated within the current request.
ModalDialogStatusSaver modalStatus = ModalDialogStatusSaver.lookup();
ModalDialogComponent modalDialog = modalStatus.getModalDialog();
boolean modalOn = modalDialog.isShowing();
boolean modalOnBeforeRequest = modalStatus.modalOnBeforeRequest();
boolean modalSwitchedOn = !modalOnBeforeRequest && modalOn;
boolean modalSwitchedOff = modalOnBeforeRequest && !modalOn;
// Check if the navigation has changed (f.i: URL typing) and so auto-close the modal (if was opened).
if (modalOn) {
if (!modalSwitchedOn) {
NavigationManager navMgr = NavigationManager.lookup();
boolean navigationChanged = false;
boolean configEnabled = navMgr.isShowingConfig();
boolean wasConfigEnabled = modalStatus.isConfigEnabled();
String currentWorkspaceId = navMgr.getCurrentWorkspaceId();
String oldWorkspaceId = modalStatus.getCurrentWorkspaceId();
Long currentSectionId = navMgr.getCurrentSectionId();
Long oldSectionId = modalStatus.getCurrentSectionId();
if (configEnabled != wasConfigEnabled) navigationChanged = true;
if (ComparatorUtils.compare(currentWorkspaceId, oldWorkspaceId, 1) != 0) navigationChanged = true;
if (ComparatorUtils.compare(currentSectionId, oldSectionId, 1) != 0) navigationChanged = true;
if (navigationChanged) {
modalDialog.hide();
return true;
}
}
// Preserve panel session context when the modal has been activated inside a panel.
Panel panel = getCurrentPanel(request);
if (panel != null) request.setAttribute(Parameters.RENDER_PANEL, panel);
}
// If modal has been switched off, return new screen response without ajax so as to
// force to repaint all screen without the component.
if (modalSwitchedOff) {
controllerStatus.setResponse(new ShowCurrentScreenResponse());
return true;
}
// If no AJAX then just return the current response
// The modal window is embedded into content.jsp so it will be displayed if the whole screen is repainted.
String ajaxParam = request.getParameter(Parameters.AJAX_ACTION);
if (ajaxParam == null || !Boolean.valueOf(ajaxParam).booleanValue()) return true;
// If the modal window is on then show it.
// The AJAX response varies depending whether the modal window is rendered for the first time or
// it's a response inside the modal window.
if (modalOn) {
if (modalSwitchedOn) controllerStatus.setResponse(new ShowComponentAjaxResponse(modalDialog));
else controllerStatus.setResponse(new ShowComponentAjaxResponse(modalDialog.getCurrentComponent()));
}
return true;
}