Author: rich
Date: Sat Aug 21 15:52:10 2004
New Revision: 36678

Added:
   
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/faces/PageFlowViewHandler.java
   (contents, props changed)
Modified:
   incubator/beehive/trunk/BUILDING.txt
   
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/Diagnostics.java
   
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/faces/PageFlowApplication.java
   
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/faces/PageFlowNavigationHandler.java
   
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/InternalConstants.java
   
incubator/beehive/trunk/netui/src/scoping/org/apache/beehive/netui/pageflow/scoping/internal/ScopedRequestImpl.java
Log:
Fixed JSF integration to avoid:

    - Infinite loop of server forwards when raising a page flow action that 
forwards to another .faces URI, and when JSF is set to save state on the client 
(javax.faces.STATE_SAVING_METHOD Servlet context param is set to "client").

    - IllegalStateException for forwarding an already-committed request, in the 
same case as above but without client-side state.
    
    DRT: netui server (WinXP)
    BB: self



Modified: incubator/beehive/trunk/BUILDING.txt
==============================================================================
--- incubator/beehive/trunk/BUILDING.txt        (original)
+++ incubator/beehive/trunk/BUILDING.txt        Sat Aug 21 15:52:10 2004
@@ -11,7 +11,7 @@
 
   http://java.sun.com/j2se/1.5.0/snapshots/
 
-be sure to have version 1.5.0-beta2-b51 or later.  Earlier versions of JDK 1.5 
will not 
+be sure to have version 1.5.0-beta3-b59 or later.  Earlier versions of JDK 1.5 
will not 
 work correctly.
 
 Set the BEEHIVE_HOME environment variable to point to your root beehive 

Modified: 
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/Diagnostics.java
==============================================================================
--- 
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/Diagnostics.java
       (original)
+++ 
incubator/beehive/trunk/netui/src/compiler/org/apache/beehive/netui/compiler/Diagnostics.java
       Sat Aug 21 15:52:10 2004
@@ -46,22 +46,19 @@
     
     public void addError( AnnotationMirror ann, String messageKey, Object ... 
args )
     {
-        // @TODO need something from mirror here -- need to get the 
SourcePosition of an annotation
-        System.err.println( "error on annotation " + ann + ": " + getMessage( 
messageKey, args ) );
+        _env.getMessager().printError( ann.getPosition(), getMessage( 
messageKey, args ) );
         _hadErrors = true;
     }
     
     public void addErrorArrayArgs( AnnotationMirror ann, String messageKey, 
Object [] args )
     {
-        // @TODO need something from mirror here -- need to get the 
SourcePosition of an annotation
-        System.err.println( "error on annotation " + ann + ": " + getMessage( 
messageKey, args ) );
+        _env.getMessager().printError( ann.getPosition(), getMessage( 
messageKey, args ) );
         _hadErrors = true;
     }
     
     public void addError( AnnotationValue annVal, String messageKey, Object 
... args )
     {
-        // @TODO need something from mirror here -- need to get the 
SourcePosition of an annotation
-        System.err.println( "error on annotation value " + annVal + ": " + 
getMessage( messageKey, args ) );
+        _env.getMessager().printError( annVal.getPosition(), getMessage( 
messageKey, args ) );
         _hadErrors = true;
     }
     
@@ -72,14 +69,12 @@
     
     public void addWarning( AnnotationMirror ann, String messageKey, Object 
... args )
     {
-        // @TODO need something from mirror here -- need to get the 
SourcePosition of an annotation
-        System.err.println( "warning on annotation " + ann + ": " + 
getMessage( messageKey, args ) );
+        _env.getMessager().printWarning( ann.getPosition(), getMessage( 
messageKey, args ) );
     }
     
     public void addWarning( AnnotationValue annVal, String messageKey, Object 
... args )
     {
-        // @TODO need something from mirror here -- need to get the 
SourcePosition of an annotation
-        System.err.println( "warning on annotation value " + annVal + ": " + 
getMessage( messageKey, args ) );
+        _env.getMessager().printWarning( annVal.getPosition(), getMessage( 
messageKey, args ) );
     }
     
     private String getMessage( String key, Object ... args )

Modified: 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/faces/PageFlowApplication.java
==============================================================================
--- 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/faces/PageFlowApplication.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/faces/PageFlowApplication.java
 Sat Aug 21 15:52:10 2004
@@ -133,7 +133,7 @@
 
     public ViewHandler getViewHandler()
     {
-        return _delegate.getViewHandler();
+        return new PageFlowViewHandler( _delegate.getViewHandler() );
     }
 
     public void setViewHandler( ViewHandler handler )

Modified: 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/faces/PageFlowNavigationHandler.java
==============================================================================
--- 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/faces/PageFlowNavigationHandler.java
   (original)
+++ 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/faces/PageFlowNavigationHandler.java
   Sat Aug 21 15:52:10 2004
@@ -15,6 +15,7 @@
 import org.apache.beehive.netui.pageflow.PageFlowUtils;
 import org.apache.beehive.netui.pageflow.PageFlowConstants;
 import org.apache.beehive.netui.pageflow.FlowControllerFactory;
+import org.apache.beehive.netui.pageflow.internal.InternalConstants;
 import org.apache.beehive.netui.util.logging.Logger;
 
 
@@ -23,6 +24,7 @@
     extends NavigationHandler
 {
     private static final Logger _log = Logger.getInstance( 
PageFlowNavigationHandler.class );
+    static final String ALREADY_FORWARDED_ATTR = InternalConstants.ATTR_PREFIX 
+ "navHandled"; 
     
     private NavigationHandler _baseHandler;
 
@@ -48,6 +50,17 @@
         {
             HttpServletRequest httpRequest = ( HttpServletRequest ) request;
             HttpServletResponse httpResponse = ( HttpServletResponse ) 
response;
+            
+            //
+            // If we're coming in on a forwarded request from this 
NavigationHandler, bail out; we don't want to
+            // forward again.
+            //
+            if ( httpRequest.getAttribute( ALREADY_FORWARDED_ATTR ) != null )
+            {
+                httpRequest.removeAttribute( ALREADY_FORWARDED_ATTR );
+                return;
+            }
+            
             ServletContext servletContext = ( ServletContext ) extContext;
             PageFlowController pfc = 
FlowControllerFactory.getPageFlowForRequest( httpRequest, httpResponse, 
servletContext );
             PageFlowUtils.getCurrentPageFlow( httpRequest );
@@ -56,26 +69,28 @@
             {
                 if ( outcome != null )
                 {
+                    String actionURI = outcome + 
PageFlowConstants.ACTION_EXTENSION;
+                    
+                    if ( _log.isDebugEnabled() )
+                    {
+                        _log.debug( "Forwarding to " + actionURI );
+                    }
+                    
+                    context.responseComplete();
+                    context.setViewRoot( null );
+                    httpRequest.setAttribute( ALREADY_FORWARDED_ATTR, 
Boolean.TRUE );
+                    
                     try
                     {
-                        String actionURI = outcome + 
PageFlowConstants.ACTION_EXTENSION;
-                        
-                        if ( _log.isDebugEnabled() )
-                        {
-                            _log.debug( "Forwarding to " + actionURI );
-                        }
-                        
                         httpRequest.getRequestDispatcher( actionURI ).forward( 
httpRequest, httpResponse );
                     }
                     catch ( IOException e )
                     {
-                        // TODO: log
-                        e.printStackTrace();
+                        _log.error( "Could not forward to " + actionURI, e );
                     }
                     catch ( ServletException e )
                     {
-                        // TODO: log
-                        e.printStackTrace();
+                        _log.error( "Could not forward to " + actionURI, 
e.getRootCause() );
                     }
                 }
 

Added: 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/faces/PageFlowViewHandler.java
==============================================================================
--- (empty file)
+++ 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/faces/PageFlowViewHandler.java
 Sat Aug 21 15:52:10 2004
@@ -0,0 +1,100 @@
+/*
+ * B E A   S Y S T E M S
+ * Copyright 2002-2004  BEA Systems, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.netui.pageflow.faces;
+
+import javax.faces.application.ViewHandler;
+import javax.faces.context.FacesContext;
+import javax.faces.component.UIViewRoot;
+import javax.faces.FacesException;
+import javax.servlet.http.HttpServletRequest;
+import java.util.Locale;
+import java.io.IOException;
+
+
+/**
+ * Delegates in all cases except [EMAIL PROTECTED] #restoreView}, which 
prevents view restoration if we're in a request
+ * forwarded by [EMAIL PROTECTED] PageFlowNavigationHandler}.
+ */ 
+class PageFlowViewHandler
+        extends ViewHandler
+{
+    private ViewHandler _delegate;
+
+    public PageFlowViewHandler( ViewHandler delegate )
+    {
+        _delegate = delegate;
+    }
+    
+    public Locale calculateLocale(FacesContext context)
+    {
+        return _delegate.calculateLocale( context );
+    }
+
+    public String calculateRenderKitId(FacesContext context)
+    {
+        return _delegate.calculateRenderKitId( context );
+    }
+
+    public UIViewRoot createView(FacesContext context, String viewId)
+    {
+        return _delegate.createView( context, viewId );
+    }
+
+    public String getActionURL(FacesContext context, String viewId)
+    {
+        return _delegate.getActionURL( context, viewId );
+    }
+
+    public String getResourceURL(FacesContext context, String path)
+    {
+        return _delegate.getResourceURL( context, path );
+    }
+
+    public void renderView(FacesContext context, UIViewRoot viewToRender)
+        throws IOException, FacesException
+    {
+        _delegate.renderView( context, viewToRender );
+    }
+
+    /**
+     * If we are in a request forwarded by [EMAIL PROTECTED] 
PageFlowNavigationHandler}, returns <code>null</code>; otherwise,
+     * delegates to the base ViewHandler.
+     */ 
+    public UIViewRoot restoreView(FacesContext context, String viewId)
+    {
+        Object request = context.getExternalContext().getRequest();
+        
+        if ( request instanceof HttpServletRequest )
+        {
+            HttpServletRequest httpRequest = ( HttpServletRequest ) request;
+            
+            if ( httpRequest.getAttribute( 
PageFlowNavigationHandler.ALREADY_FORWARDED_ATTR ) != null )
+            {
+                return null;
+            }
+        }
+        
+        return _delegate.restoreView( context, viewId );
+    }
+
+    public void writeState(FacesContext context) throws IOException
+    {
+        _delegate.writeState( context );
+    }
+}

Modified: 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/InternalConstants.java
==============================================================================
--- 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/InternalConstants.java
        (original)
+++ 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/InternalConstants.java
        Sat Aug 21 15:52:10 2004
@@ -36,4 +36,6 @@
     
     public static final String SHARED_FLOW_MODULE_PREFIX = "/-";
     public static final String SHARED_FLOW_ROOT_MODULE = "/-webappRoot";
+    
+    public static final String ATTR_PREFIX = "_netui:";
 }

Modified: 
incubator/beehive/trunk/netui/src/scoping/org/apache/beehive/netui/pageflow/scoping/internal/ScopedRequestImpl.java
==============================================================================
--- 
incubator/beehive/trunk/netui/src/scoping/org/apache/beehive/netui/pageflow/scoping/internal/ScopedRequestImpl.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/scoping/org/apache/beehive/netui/pageflow/scoping/internal/ScopedRequestImpl.java
 Sat Aug 21 15:52:10 2004
@@ -72,16 +72,7 @@
     {
         super( request );
         _scopedContainer = new ScopedAttributeContainer( scopeKey );
-
-        if ( overrideRequestURI != null )
-        {
-            _requestURI = request.getContextPath() + overrideRequestURI;
-        }
-        else
-        {
-            _requestURI = request.getContextPath();
-        }
-
+        _requestURI = overrideRequestURI != null ? overrideRequestURI : "";
         _context = context;
         _useScopedSession = useScopedSession;
     }

Reply via email to