myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mat...@apache.org
Subject svn commit: r612935 - in /myfaces/trinidad/branches/1.2.5.1-branch: trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/ trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/ trinidad-impl/src/main/java/org/apache/myf...
Date Thu, 17 Jan 2008 19:20:27 GMT
Author: matzew
Date: Thu Jan 17 11:20:26 2008
New Revision: 612935

URL: http://svn.apache.org/viewvc?rev=612935&view=rev
Log:
TRINIDAD-905

Modified:
    myfaces/trinidad/branches/1.2.5.1-branch/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXGroupTemplate.java
    myfaces/trinidad/branches/1.2.5.1-branch/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXIteratorTemplate.java
    myfaces/trinidad/branches/1.2.5.1-branch/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXSwitcherTemplate.java
    myfaces/trinidad/branches/1.2.5.1-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponent.java
    myfaces/trinidad/branches/1.2.5.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/DialogServiceImpl.java

Modified: myfaces/trinidad/branches/1.2.5.1-branch/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXGroupTemplate.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.5.1-branch/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXGroupTemplate.java?rev=612935&r1=612934&r2=612935&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.5.1-branch/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXGroupTemplate.java
(original)
+++ myfaces/trinidad/branches/1.2.5.1-branch/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXGroupTemplate.java
Thu Jan 17 11:20:26 2008
@@ -30,7 +30,8 @@
  * <p>
  * @version $Name:  $ ($Revision: 429530 $) $Date: 2006-08-07 18:44:54 -0600 (Mon, 07 Aug
2006) $
  */
-abstract public class UIXGroupTemplate extends UIXComponentBase
+abstract public class UIXGroupTemplate extends UIXComponentBase implements FlattenedComponent
+
 {
   /**
    * Overridden to return true.
@@ -43,6 +44,44 @@
   }
 
   /**
+   * Sets up the grouping context and processes all of the
+   * UIXGroup's children
+   */
+  public <S> boolean processFlattenedChildren(
+    FacesContext context,
+    ComponentProcessingContext cpContext,
+    ComponentProcessor<S> childProcessor,
+    S callBackContext
+    ) throws IOException
+  {
+    cpContext.pushGroup();
+    
+    try
+    {
+      // bump up the group depth and render all of the children
+      return UIXComponent.processFlattenedChildren(context,
+                                                   cpContext,
+                                                   childProcessor,
+                                                   this.getChildren(),
+                                                   callBackContext);
+    }
+    finally
+    {
+      cpContext.popGroup();      
+    }
+  }
+
+  /**
+   * Returns <code>true</code> if this FlattenedComponent is currently flattening
its children
+   * @param context FacesContext
+   * @return <code>true</code> if this FlattenedComponent is currently flattening
its children
+   */
+  public boolean isFlatteningChildren(FacesContext context)
+  {
+    return true;
+  }
+
+  /**
    * Renders the children in their raw form.
    * There is no Renderer for this component because it has no
    * visual representation or any sort of layout for its children.
@@ -67,4 +106,5 @@
     }
   }
 }
+
 

Modified: myfaces/trinidad/branches/1.2.5.1-branch/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXIteratorTemplate.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.5.1-branch/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXIteratorTemplate.java?rev=612935&r1=612934&r2=612935&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.5.1-branch/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXIteratorTemplate.java
(original)
+++ myfaces/trinidad/branches/1.2.5.1-branch/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXIteratorTemplate.java
Thu Jan 17 11:20:26 2008
@@ -41,7 +41,7 @@
  * If {@link #getRows()} returns 0, then the iteration continues until 
  * there are no more elements in the underlying data.
  */
-public abstract class UIXIteratorTemplate extends UIXCollection
+public abstract class UIXIteratorTemplate extends UIXCollection implements FlattenedComponent
 {
 
 /**/  abstract public int getFirst();
@@ -58,6 +58,49 @@
   }
 
   /**
+   * Sets up the iteration context for each child and processes it
+   */
+  public <S> boolean processFlattenedChildren(
+    final FacesContext context,
+    ComponentProcessingContext cpContext,
+    final ComponentProcessor<S> childProcessor,
+    final S callbackContext) throws IOException
+  {
+    Runner runner = new Runner(cpContext)
+    {
+      @Override
+      protected void process(UIComponent kid, ComponentProcessingContext cpContext) throws
IOException
+      {
+        childProcessor.processComponent(context, cpContext, kid, callbackContext);
+      }
+    };
+    boolean processedChildren = runner.run();
+    Exception exp = runner.exception;
+    if (exp != null)
+    {
+      if (exp instanceof RuntimeException)
+        throw (RuntimeException) exp;
+
+      if (exp instanceof IOException)
+        throw (IOException) exp;
+      throw new IllegalStateException(exp);
+    }
+    
+    return processedChildren;
+  }
+
+  /**
+   * Returns <code>true</code> if this FlattenedComponent is currently flattening
its children
+   * @param context FacesContext
+   * @return <code>true</code> if this FlattenedComponent is currently flattening
its children
+   */
+  public boolean isFlatteningChildren(FacesContext context)
+  {
+    // if we don't have a Renderer, then we're flattening
+    return (getRendererType() == null);
+  }
+
+  /**
    * Repeatedly render the children as many times as needed.
    */
   @Override
@@ -81,7 +124,8 @@
       Runner runner = new Runner()
       {
         @Override
-        protected void process(UIComponent kid) throws IOException
+        protected void process(UIComponent kid,
+                               ComponentProcessingContext cpContext) throws IOException
         {
           __encodeRecursive(context, kid);
         }
@@ -172,18 +216,30 @@
     Runner runner = new Runner()
     {
       @Override
-      protected void process(UIComponent kid)
+      protected void process(UIComponent kid, ComponentProcessingContext cpContext)
       {
-        processComponent(context, kid, phaseId);
+        UIXIterator.this.processComponent(context, kid, phaseId);
       }
     };
     runner.run();
   }
-
-  private abstract class Runner
+  
+  private abstract class Runner implements ComponentProcessor<Object>
   {
-    public final void run()
+    public Runner()
+    {
+      this(null);
+    }
+
+    public Runner(ComponentProcessingContext cpContext)
+    {
+      _cpContext = cpContext;
+    }
+    
+    public final boolean run()
     {
+      FacesContext context = FacesContext.getCurrentInstance();
+      
       List<UIComponent> stamps = getStamps();
       int oldIndex = getRowIndex();
       int first = getFirst();
@@ -191,6 +247,9 @@
       int end = (rows <= 0) //show everything
         ? Integer.MAX_VALUE
         : first + rows;
+      
+      boolean processedChild = false;
+      
       try
       {
         for(int i=first; i<end; i++)
@@ -198,16 +257,16 @@
           setRowIndex(i);
           if (isRowAvailable())
           {
-            for(UIComponent stamp : stamps)
-            {
-              process(stamp);
-            }
+            // latch processedChild the first time we process a child
+            processedChild |= (_cpContext != null)
+              ? UIXComponent.processFlattenedChildren(context, _cpContext, this, stamps,
null)
+              : UIXComponent.processFlattenedChildren(context, this, stamps, null);
           }
           else
             break;
         }
       }
-      catch (Exception e)
+      catch (IOException e)
       {
         exception = e;
       }
@@ -215,10 +274,39 @@
       {
         setRowIndex(oldIndex);
       }
+      
+      return processedChild;
     }
-    
+
+    /**
+     * Sets up the context for the child and processes it
+     */
+    public void processComponent(
+      FacesContext context,
+      ComponentProcessingContext cpContext,
+      UIComponent component,
+      Object callbackContext) throws IOException
+    {
+      try
+      {
+        process(component, cpContext);
+      }
+      catch (IOException ioe)
+      {
+        throw ioe;
+      }
+      catch (Exception e)
+      {
+        exception = e;
+      }
+    }
+
+    protected abstract void process(UIComponent comp, ComponentProcessingContext cpContext)
+      throws Exception;
+
     public Exception exception = null;
-    protected abstract void process(UIComponent comp) throws Exception;
+
+    private final ComponentProcessingContext _cpContext;
   }
 
   @Override

Modified: myfaces/trinidad/branches/1.2.5.1-branch/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXSwitcherTemplate.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.5.1-branch/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXSwitcherTemplate.java?rev=612935&r1=612934&r2=612935&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.5.1-branch/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXSwitcherTemplate.java
(original)
+++ myfaces/trinidad/branches/1.2.5.1-branch/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXSwitcherTemplate.java
Thu Jan 17 11:20:26 2008
@@ -29,7 +29,7 @@
  * <p>
  * @version $Name:  $ ($Revision$) $Date$
  */
-abstract public class UIXSwitcherTemplate extends UIXComponentBase
+abstract public class UIXSwitcherTemplate extends UIXComponentBase implements FlattenedComponent
 {
 /**/ // Abstract methods implemented by code gen
 /**/  abstract public String getFacetName();
@@ -69,6 +69,36 @@
       facet.processUpdates(context);
   }
 
+  /**
+   * Processes the selected switcher facet
+   */
+  public <S> boolean processFlattenedChildren(
+    final FacesContext context,
+    ComponentProcessingContext cpContext,
+    final ComponentProcessor<S> childProcessor,
+    final S callbackContext) throws IOException
+  {
+    UIComponent facet = _getFacet();
+    
+    if (facet != null)
+      return UIXComponent.processFlattenedChildren(context,
+                                                   cpContext,
+                                                   childProcessor,
+                                                   facet,
+                                                   callbackContext);
+    else
+      return false;
+  }
+
+  /**
+   * Returns <code>true</code> if this FlattenedComponent is currently flattening
its children
+   * @param context FacesContext
+   * @return <code>true</code> if this FlattenedComponent is currently flattening
its children
+   */
+  public boolean isFlatteningChildren(FacesContext context)
+  {
+    return true;
+  }
 
   /**
    * Only render the currently active facet.
@@ -113,4 +143,5 @@
   }
 
 }
+
 

Modified: myfaces/trinidad/branches/1.2.5.1-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponent.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.5.1-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponent.java?rev=612935&r1=612934&r2=612935&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.5.1-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponent.java
(original)
+++ myfaces/trinidad/branches/1.2.5.1-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponent.java
Thu Jan 17 11:20:26 2008
@@ -18,10 +18,14 @@
  */
 package org.apache.myfaces.trinidad.component;
 
+import java.io.IOException;
+
 import javax.faces.component.UIComponent;
 
 import javax.el.MethodExpression;
 
+import javax.faces.context.FacesContext;
+
 import org.apache.myfaces.trinidad.bean.FacesBean;
 import org.apache.myfaces.trinidad.event.AttributeChangeListener;
 
@@ -30,6 +34,165 @@
  */
 abstract public class UIXComponent extends UIComponent
 {
+  /**
+   * Helper function called by Renderers to iterate over a flattened view of a group of
+   * potentially FlattenedComponent instances rooted at a single child of the component that
+   * the Renderer is encoding, invoking the <code>childProcessor</code> with
its
+   * <code>callbackContext</code> on each renderable instance.
+   * <p>
+   * If the child is a FlattenedComponent, the <code>childProcessor</code> will
+   * be called on each of that FlattenedComponent's children, recursing if those children
are
+   * themselves FlattenedComponents, otherwise, the <code>childProcessor</code>
will be called on
+   * the child itself.
+   * <p>
+   * This method is typically used to flatten the contents of a facet on the FlattenedComponent
to
+   * be encoded.  If the Renderer accidentally passes in the component to be encoded instead
of one
+   * of its children, the result will almost certainly be an infinite recursion and stack
overflow.
+   * @see UIXComponent#processFlattenedChildren(FacesContext, ComponentProcessor, Iterable,
Object)
+   * @see UIXComponent#processFlattenedChildren(FacesContext, ComponentProcessingContext,
ComponentProcessor, UIComponent, Object)
+   * @see UIXComponent#processFlattenedChildren(FacesContext, ComponentProcessingContext,
ComponentProcessor, Iterable, Object)
+   * @see FlattenedComponent
+   */
+  public static <S> boolean processFlattenedChildren(
+    FacesContext context,
+    ComponentProcessor<S> childProcessor,
+    UIComponent child,
+    S callbackContext) throws IOException
+  {
+    return processFlattenedChildren(context,
+                                    new ComponentProcessingContext(),
+                                    childProcessor,
+                                    child,
+                                    callbackContext);
+  }
+
+  /**
+   * Helper function called by FlattenedComponent to iterate over a flattened view of a group
of
+   * potentially FlattenedComponent instances rooted at a single child of the FlattenedComponent,
+   * invoking the <code>childProcessor</code> with its
+   * <code>callbackContext</code> on each renderable instance.
+   * <p>
+   * If the child is a FlattenedComponent, the <code>childProcessor</code> will
+   * be called on each of that FlattenedComponent's children, recursing if those children
are
+   * themselves FlattenedComponents, otherwise, the <code>childProcessor</code>
will be called on
+   * the child itself.
+   * <p>
+   * This method is typically used to flatten the contents of a facet of the FlattenedComponent.
+   * If the FlattenedComponent accidentally passes in itself instead of one
+   * of its children, the result will almost certainly be an infinite recursion and stack
overflow.
+   * @see UIXComponent#processFlattenedChildren(FacesContext, ComponentProcessor, UIComponent,
Object)
+   * @see UIXComponent#processFlattenedChildren(FacesContext, ComponentProcessor, Iterable,
Object)
+   * @see UIXComponent#processFlattenedChildren(FacesContext, ComponentProcessingContext,
ComponentProcessor, Iterable, Object)
+   * @see FlattenedComponent
+   */
+    public static <S> boolean processFlattenedChildren(
+    FacesContext context,
+    ComponentProcessingContext cpContext,
+    ComponentProcessor<S> childProcessor,
+    UIComponent child,
+    S callbackContext) throws IOException
+  {
+    if (child.isRendered())
+    {      
+       // component is an action FlattenedComponent.  Ask it to flatten its children
+      if ((child instanceof FlattenedComponent) &&
+          ((FlattenedComponent)child).isFlatteningChildren(context))
+      {
+        return ((FlattenedComponent)child).processFlattenedChildren(context,
+                                                                    cpContext,
+                                                                    childProcessor,
+                                                                    callbackContext);
+      }
+      else
+      {
+        // not a FlattenedComponent, pass the component directly to the ComponentProcessor
+        try
+        {
+          childProcessor.processComponent(context, cpContext, child, callbackContext);
+        }
+        finally
+        {
+          // if startDepth is > 0, only the first visible child will be marked as starting
a group
+          cpContext.resetStartDepth();
+        }
+        
+        return true;
+      }
+    }
+    else
+    {
+      // component not rendered
+      return false;
+    }
+  }
+
+  /**
+   * Helper function called by Renderers to iterate over a flattened view of the
+   * children, potentially containing FlattenedComponents, of the component the Renderer
is
+   * encoding, invoking the <code>childProcessor</code> with its
+   * <code>callbackContext</code> on each renderable instance.
+   * <p>
+   * For each FlattenedComponent child, the <code>childProcessor</code> will
+   * be called on each of that FlattenedComponent's children, recursing if those children
are
+   * themselves FlattenedComponents, otherwise, the <code>childProcessor</code>
will be called on
+   * the child itself.
+   * <p>
+   * This method is typically used to flatten the children of the FlattenedComponent to
+   * be encoded.
+   * @see UIXComponent#processFlattenedChildren(FacesContext, ComponentProcessor, UIComponent,
Object)
+   * @see UIXComponent#processFlattenedChildren(FacesContext, ComponentProcessingContext,
ComponentProcessor, UIComponent, Object)
+   * @see UIXComponent#processFlattenedChildren(FacesContext, ComponentProcessingContext,
ComponentProcessor, Iterable, Object)
+   * @see FlattenedComponent
+   */
+  public static <S> boolean processFlattenedChildren(
+    FacesContext context,
+    ComponentProcessor<S> childProcessor,
+    Iterable<UIComponent> children,
+    S callbackContext) throws IOException
+  {
+    return processFlattenedChildren(context,
+                                    new ComponentProcessingContext(),
+                                    childProcessor,
+                                    children,
+                                    callbackContext);
+  }
+
+  /**
+   * Helper function called by FlattenedComponents to iterate over a flattened view of their
+   * children, potentially themselves FlattenedComponents, invoking the <code>childProcessor</code>
+   * with its <code>callbackContext</code> on each renderable instance.
+   * <p>
+   * For each FlattenedComponent child, the <code>childProcessor</code> will
+   * be called on each of that FlattenedComponent's children, recursing if those children
are
+   * themselves FlattenedComponents, otherwise, the <code>childProcessor</code>
will be called on
+   * the child itself.
+   * @see UIXComponent#processFlattenedChildren(FacesContext, ComponentProcessor, UIComponent,
Object)
+   * @see UIXComponent#processFlattenedChildren(FacesContext, ComponentProcessor, Iterable,
Object)
+   * @see UIXComponent#processFlattenedChildren(FacesContext, ComponentProcessingContext,
ComponentProcessor, UIComponent, Object)
+   * @see FlattenedComponent
+   */
+  public static <S> boolean processFlattenedChildren(
+    FacesContext context,
+    ComponentProcessingContext cpContext,
+    ComponentProcessor<S> childProcessor,
+    Iterable<UIComponent> children,
+    S callbackContext) throws IOException
+  {
+    // we haven't processed a child yet
+    boolean processedChild = false;
+    
+    for (UIComponent currChild : children)
+    {
+      // latch processed child to the first child processed
+      processedChild |= processFlattenedChildren(context,
+                                                 cpContext, childProcessor,
+                                                 currChild,
+                                                 callbackContext);
+    }
+    
+    return processedChild;
+  }
+
   /**
    * Returns the FacesBean used for storing the component's state.
    */

Modified: myfaces/trinidad/branches/1.2.5.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/DialogServiceImpl.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.5.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/DialogServiceImpl.java?rev=612935&r1=612934&r2=612935&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.5.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/DialogServiceImpl.java
(original)
+++ myfaces/trinidad/branches/1.2.5.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/DialogServiceImpl.java
Thu Jan 17 11:20:26 2008
@@ -396,7 +396,7 @@
       // Save the parameters used to launch the dialog so we can
       // simulate a postback when coming back to the dialog;  and
       // write in a "returnId" with the "id" that will be used.
-      Map<String, Object> savedRequestParameters = new HashMap<String, Object>();
+      Map<String, String[]> savedRequestParameters = new HashMap<String, String[]>();
       savedRequestParameters.putAll(
             context.getExternalContext().getRequestParameterValuesMap());
       if (source != null)



Mime
View raw message