You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by sk...@apache.org on 2008/07/25 15:04:14 UTC

svn commit: r679784 - /myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/FlowViewHandler.java

Author: skitching
Date: Fri Jul 25 06:04:14 2008
New Revision: 679784

URL: http://svn.apache.org/viewvc?rev=679784&view=rev
Log:
Add the "captureNavigation" method, needed for modal dialog support.

Modified:
    myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/FlowViewHandler.java

Modified: myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/FlowViewHandler.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/FlowViewHandler.java?rev=679784&r1=679783&r2=679784&view=diff
==============================================================================
--- myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/FlowViewHandler.java (original)
+++ myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/FlowViewHandler.java Fri Jul 25 06:04:14 2008
@@ -21,6 +21,7 @@
 import java.io.IOException;
 import java.lang.reflect.Method;
 import java.util.Locale;
+import java.util.Map;
 
 import javax.faces.FacesException;
 import javax.faces.application.ViewHandler;
@@ -188,9 +189,55 @@
      * specified is the entry point for a flow but the previous view did
      * not do a FlowCall.
      */
-    public UIViewRoot createView(FacesContext context, String viewId)
+    public UIViewRoot createView(FacesContext context, String newViewId)
     {
-        FlowHandler.processAccept(context, viewId);
-        return delegate.createView(context, viewId);
+        if (isCaptureNavigation())
+        {
+            // Cache the target view in the request, but stay on current view.
+            // See documentation for method captureNavigation for more details.
+            String newViewUrl = getActionURL(context, newViewId);
+            setNewViewInfo(newViewId, newViewUrl);
+            return context.getViewRoot();
+        }
+        else
+        {
+            FlowHandler.processAccept(context, newViewId);
+            return delegate.createView(context, newViewId);
+        }
+    }
+
+    /**
+     * Enable or disable "navigation capture" for the current request.
+     * <p>
+     * When enabled, method createView will not load a new view, and will simply stay on the current
+     * view. However the information about where it _would_ have navigated to is cached in the request.
+     * <p>
+     * This is intended to be used by "modal dialog" support, so that a page which triggers a new flow
+     * can be re-rendered unaltered and instead (somehow) the new view can be loaded using a separate
+     * request from the browser (in a new window or frame).
+     * <p>
+     * This method must only be called when the current request is a postback, ie there is a
+     * "current view" to stay on.
+     */
+    public static void captureNavigation(boolean state)
+    {
+        FacesContext fc = FacesContext.getCurrentInstance();
+        Map reqMap = fc.getExternalContext().getRequestMap();
+        reqMap.put("captureNavigation", Boolean.valueOf(state));
+    }
+
+    private static boolean isCaptureNavigation()
+    {
+        FacesContext fc = FacesContext.getCurrentInstance();
+        Map reqMap = fc.getExternalContext().getRequestMap();
+        return Boolean.TRUE.equals(reqMap.get("captureNavigation"));
+    }
+
+    private static void setNewViewInfo(String viewId, String viewUrl)
+    {
+        FacesContext fc = FacesContext.getCurrentInstance();
+        Map reqMap = fc.getExternalContext().getRequestMap();
+        reqMap.put("orchestraFlowId", viewId);
+        reqMap.put("orchestraFlowUrl", viewUrl);
     }
 }