diff --git a/nuxeo-platform-ui-web/src/main/java/org/nuxeo/ecm/platform/ui/web/rest/FancyNavigationHandler.java b/nuxeo-platform-ui-web/src/main/java/org/nuxeo/ecm/platform/ui/web/rest/FancyNavigationHandler.java --- a/nuxeo-platform-ui-web/src/main/java/org/nuxeo/ecm/platform/ui/web/rest/FancyNavigationHandler.java +++ b/nuxeo-platform-ui-web/src/main/java/org/nuxeo/ecm/platform/ui/web/rest/FancyNavigationHandler.java @@ -22,7 +22,10 @@ import java.io.IOException; import java.util.Map; +import javax.faces.FacesException; import javax.faces.application.NavigationHandler; +import javax.faces.application.ViewHandler; +import javax.faces.component.UIViewRoot; import javax.faces.context.ExternalContext; import javax.faces.context.FacesContext; import javax.servlet.http.HttpServletRequest; @@ -34,9 +37,11 @@ import org.nuxeo.ecm.platform.ui.web.util.BaseURL; import org.nuxeo.runtime.api.Framework; +import com.sun.faces.util.Util; + /** - * Navigation handler that keeps outcome information available so that it can be - * used for a document view when redirecting to this context. + * Navigation handler that keeps outcome information available so that it can + * be used for a document view when redirecting to this context. * * @author Anahide Tchertchian */ @@ -58,13 +63,25 @@ // put outcome in request params httpRequest.setAttribute(URLPolicyService.POST_OUTCOME_REQUEST_KEY, outcome); + URLPolicyService pservice = null; try { - URLPolicyService pservice = Framework.getService(URLPolicyService.class); + pservice = Framework.getService(URLPolicyService.class); pservice.appendParametersToRequest(context); } catch (Exception e) { log.error("error occured while appending params to request: ", e); } + // get old root to check if it's changed + UIViewRoot oldRoot = context.getViewRoot(); baseNavigationHandler.handleNavigation(context, fromAction, outcome); + UIViewRoot newRoot = context.getViewRoot(); + boolean rootChanged = !oldRoot.equals(newRoot); + if (outcome != null && !context.getResponseComplete() && !rootChanged + && pservice != null) { + // navigation was not done => maybe a hot reload issue: perform + // navigation again using local code because it uses information + // from the StaticNavigationHandler that is hot-reloaded correctly + handleHotReloadNavigation(pservice, context, fromAction, outcome); + } // XXX AT: force redirect if outcome is null so that url can be // re-written except in an ajax request Map map = eContext.getRequestParameterMap(); @@ -88,4 +105,22 @@ } } } + + protected void handleHotReloadNavigation(URLPolicyService pservice, + FacesContext context, String fromAction, String outcome) { + String viewId = pservice.getViewIdFromOutcome(outcome, null); + ExternalContext extContext = context.getExternalContext(); + if (viewId != null) { + ViewHandler viewHandler = Util.getViewHandler(context); + // always redirect + String newPath = viewHandler.getActionURL(context, viewId); + try { + extContext.redirect(extContext.encodeActionURL(newPath)); + } catch (java.io.IOException ioe) { + throw new FacesException(ioe.getMessage(), ioe); + } + context.responseComplete(); + } + } + }