myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r991981 - in /myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/component/html/ext: AbstractHtmlDataTable.java HtmlDataTableHack.java _DetailStampFacetAndChildrenIterator.java
Date Thu, 02 Sep 2010 15:30:36 GMT
Author: lu4242
Date: Thu Sep  2 15:30:36 2010
New Revision: 991981

URL: http://svn.apache.org/viewvc?rev=991981&view=rev
Log:
TOMAHAWK-1545 Components inside detailStamp facet requires clientId reset each time setRowIndex
is called

Added:
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/component/html/ext/_DetailStampFacetAndChildrenIterator.java
Modified:
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/component/html/ext/AbstractHtmlDataTable.java
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/component/html/ext/HtmlDataTableHack.java

Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/component/html/ext/AbstractHtmlDataTable.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/component/html/ext/AbstractHtmlDataTable.java?rev=991981&r1=991980&r2=991981&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/component/html/ext/AbstractHtmlDataTable.java
(original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/component/html/ext/AbstractHtmlDataTable.java
Thu Sep  2 15:30:36 2010
@@ -23,11 +23,9 @@ import java.sql.ResultSet;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 import java.util.StringTokenizer;
 
 import javax.faces.application.Application;
@@ -104,6 +102,8 @@ public abstract class AbstractHtmlDataTa
     public static final String SPACER_FACET_NAME = "spacer";
     public static final String NEWSPAPER_ORIENTATION_PROPERTY = "newspaperOrientation";
 
+    public static final String DETAIL_STAMP_FACET_NAME = "detailStamp";
+
     private Map _preservedDataModel = new HashMap();
 
     private String _forceIdIndexFormula = null;
@@ -120,7 +120,7 @@ public abstract class AbstractHtmlDataTa
 
     private Map _expandedNodes = new HashMap();
 
-    private Map _detailRowStates = new HashMap();
+    //private Map _detailRowStates = new HashMap();
 
     private TableContext _tableContext = null;
 
@@ -202,21 +202,21 @@ public abstract class AbstractHtmlDataTa
 
     public void setRowIndex(int rowIndex)
     {
-        FacesContext facesContext = FacesContext.getCurrentInstance();
+        //FacesContext facesContext = FacesContext.getCurrentInstance();
 
         if (rowIndex < -1)
         {
             throw new IllegalArgumentException("rowIndex is less than -1");
         }
 
-        UIComponent facet = getFacet(HtmlTableRenderer.DETAIL_STAMP_FACET_NAME);
+        //UIComponent facet = getFacet(HtmlTableRenderer.DETAIL_STAMP_FACET_NAME);
         /*Just for obtaining an iterator which must be passed to saveDescendantComponentStates()*/
-        Set set = new HashSet();
-        set.add(facet);
-        if (getRowIndex() != -1 && facet != null)
-        {
-            _detailRowStates.put(getClientId(facesContext), saveDescendantComponentStates(set.iterator(),
false));
-        }
+        //Set set = new HashSet();
+        //set.add(facet);
+        //if (getRowIndex() != -1 && facet != null)
+        //{
+        //    _detailRowStates.put(getClientId(facesContext), saveDescendantComponentStates(set.iterator(),
false));
+        //}
 
         String rowIndexVar = getRowIndexVar();
         String rowCountVar = getRowCountVar();
@@ -279,14 +279,14 @@ public abstract class AbstractHtmlDataTa
             super.setRowIndex(rowIndex);
         }
 
-        if (rowIndex != -1 && facet != null)
-        {
-            Object rowState = _detailRowStates.get(getClientId(facesContext));
+        //if (rowIndex != -1 && facet != null)
+        //{
+        //    Object rowState = _detailRowStates.get(getClientId(facesContext));
 
-            restoreDescendantComponentStates(set.iterator(),
-                    rowState, false);
+        //    restoreDescendantComponentStates(set.iterator(),
+        //            rowState, false);
 
-        }
+        //}
 
         if (_varDetailToggler != null)
         {
@@ -295,6 +295,33 @@ public abstract class AbstractHtmlDataTa
         }
     }
 
+    protected Object saveDescendantComponentStates()
+    {
+        if (!getFacets().isEmpty())
+        {
+            UIComponent detailStampFacet = getFacet(DETAIL_STAMP_FACET_NAME); 
+            if (detailStampFacet != null)
+            {
+                return saveDescendantComponentStates(new _DetailStampFacetAndChildrenIterator(detailStampFacet,
getChildren()), false);
+            }
+        }
+        return super.saveDescendantComponentStates();
+    }
+    
+    protected void restoreDescendantComponentStates(Object state)
+    {
+        if (!getFacets().isEmpty())
+        {
+            UIComponent detailStampFacet = getFacet(DETAIL_STAMP_FACET_NAME); 
+            if (detailStampFacet != null)
+            {
+                restoreDescendantComponentStates(new _DetailStampFacetAndChildrenIterator(detailStampFacet,
getChildren()), state, false);
+                return;
+            }
+        }
+        super.restoreDescendantComponentStates(state);
+    }
+
     public void processDecodes(FacesContext context)
     {
         if (!isRendered())
@@ -305,9 +332,23 @@ public abstract class AbstractHtmlDataTa
         // We must remove and then replace the facet so that
         // it is not processed by default facet handling code
         //
-        Object facet = getFacets().remove(HtmlTableRenderer.DETAIL_STAMP_FACET_NAME);
-        super.processDecodes(context);
-        if ( facet != null ) getFacets().put(HtmlTableRenderer.DETAIL_STAMP_FACET_NAME, (UIComponent)facet);
+        //Object facet = getFacets().remove(HtmlTableRenderer.DETAIL_STAMP_FACET_NAME);
+        //super.processDecodes(context);
+        //if ( facet != null ) getFacets().put(HtmlTableRenderer.DETAIL_STAMP_FACET_NAME,
(UIComponent)facet);
+        setRowIndex(-1);
+        processFacets(context, PROCESS_DECODES);
+        processColumnFacets(context, PROCESS_DECODES);
+        processColumnChildren(context, PROCESS_DECODES);
+        setRowIndex(-1);
+        try
+        {
+            decode(context);
+        }
+        catch (RuntimeException e)
+        {
+            context.renderResponse();
+            throw e;
+        }
 
         setRowIndex(-1);
         processColumns(context, PROCESS_DECODES);
@@ -315,6 +356,101 @@ public abstract class AbstractHtmlDataTa
         processDetails(context, PROCESS_DECODES);
         setRowIndex(-1);
     }
+    
+    private void processFacets(FacesContext context, int processAction)
+    {
+        for (Iterator it = getFacets().entrySet().iterator(); it.hasNext(); )
+        {
+            Map.Entry entry = (Map.Entry) it.next();
+            if (!DETAIL_STAMP_FACET_NAME.equals((String)entry.getKey()))
+            {
+                process(context, (UIComponent) entry.getValue(), processAction);
+            }
+        }
+    }
+
+    /**
+     * Invoke the specified phase on all facets of all UIColumn children of this component.
Note that no methods are
+     * called on the UIColumn child objects themselves.
+     * 
+     * @param context
+     *            is the current faces context.
+     * @param processAction
+     *            specifies a JSF phase: decode, validate or update.
+     */
+    private void processColumnFacets(FacesContext context, int processAction)
+    {
+        for (Iterator childIter = getChildren().iterator(); childIter.hasNext();)
+        {
+            UIComponent child = (UIComponent) childIter.next();
+            if (child instanceof UIColumn)
+            {
+                if (!child.isRendered())
+                {
+                    //Column is not visible
+                    continue;
+                }
+                for (Iterator facetsIter = child.getFacets().values()
+                        .iterator(); facetsIter.hasNext();)
+                {
+                    UIComponent facet = (UIComponent) facetsIter.next();
+                    process(context, facet, processAction);
+                }
+            }
+        }
+    }
+
+    /**
+     * Invoke the specified phase on all non-facet children of all UIColumn children of this
component. Note that no
+     * methods are called on the UIColumn child objects themselves.
+     * 
+     * @param context
+     *            is the current faces context.
+     * @param processAction
+     *            specifies a JSF phase: decode, validate or update.
+     */
+    private void processColumnChildren(FacesContext context, int processAction)
+    {
+        int first = getFirst();
+        int rows = getRows();
+        int last;
+        if (rows == 0)
+        {
+            last = getRowCount();
+        }
+        else
+        {
+            last = first + rows;
+        }
+        for (int rowIndex = first; last==-1 || rowIndex < last; rowIndex++)
+        {
+            setRowIndex(rowIndex);
+
+            //scrolled past the last row
+            if (!isRowAvailable())
+                break;
+
+            for (Iterator it = getChildren().iterator(); it.hasNext();)
+            {
+                UIComponent child = (UIComponent) it.next();
+                if (child instanceof UIColumn)
+                {
+                    if (!child.isRendered())
+                    {
+                        //Column is not visible
+                        continue;
+                    }
+                    for (Iterator columnChildIter = child.getChildren()
+                            .iterator(); columnChildIter.hasNext();)
+                    {
+                        UIComponent columnChild = (UIComponent) columnChildIter
+                                .next();
+                        process(context, columnChild, processAction);
+                    }
+                }
+            }
+        }
+    }
 
     /**
      * @param context
@@ -377,14 +513,19 @@ public abstract class AbstractHtmlDataTa
 
                 process(context, facet, processAction);
 
-                if ( rowIndex == (last - 1) )
-                {
-                    Set set = new HashSet();
-                    set.add(facet);
-                    _detailRowStates.put(
-                            getClientId(FacesContext.getCurrentInstance()),
-                                saveDescendantComponentStates(set.iterator(),false));
-                }
+                // This code comes from TOMAHAWK-493, but really the problem was caused by
+                // TOMAHAWK-1534, by a bad comparison of rowIndex. The solution proposed
is override
+                // the default iterator for save/restore on HtmlDataTableHack.setRowIndex(),
to
+                // include the detailStamp. In this way, we'll be sure that the state is
correctly
+                // saved and the component clientId is reset for all components that requires
it
+                //if ( rowIndex == (last - 1) )
+                //{
+                //    Set set = new HashSet();
+                //    set.add(facet);
+                //    _detailRowStates.put(
+                //            getClientId(FacesContext.getCurrentInstance()),
+                //                saveDescendantComponentStates(set.iterator(),false));
+                //}
             }
         }
     }
@@ -443,9 +584,14 @@ public abstract class AbstractHtmlDataTa
         // We must remove and then replace the facet so that
         // it is not processed by default facet handling code
         //
-        Object facet = getFacets().remove(HtmlTableRenderer.DETAIL_STAMP_FACET_NAME);
-        super.processValidators(context);
-        if ( facet != null ) getFacets().put(HtmlTableRenderer.DETAIL_STAMP_FACET_NAME,(UIComponent)
facet);
+        //Object facet = getFacets().remove(HtmlTableRenderer.DETAIL_STAMP_FACET_NAME);
+        //super.processValidators(context);
+        //if ( facet != null ) getFacets().put(HtmlTableRenderer.DETAIL_STAMP_FACET_NAME,(UIComponent)
facet);
+        setRowIndex(-1);
+        processFacets(context, PROCESS_VALIDATORS);
+        processColumnFacets(context, PROCESS_VALIDATORS);
+        processColumnChildren(context, PROCESS_VALIDATORS);
+        setRowIndex(-1);
 
         processColumns(context, PROCESS_VALIDATORS);
         setRowIndex(-1);
@@ -468,9 +614,15 @@ public abstract class AbstractHtmlDataTa
         // We must remove and then replace the facet so that
         // it is not processed by default facet handling code
         //
-        Object facet = getFacets().remove(HtmlTableRenderer.DETAIL_STAMP_FACET_NAME);
-        super.processUpdates(context);
-        if ( facet != null ) getFacets().put(HtmlTableRenderer.DETAIL_STAMP_FACET_NAME,(UIComponent)
facet);
+        //Object facet = getFacets().remove(HtmlTableRenderer.DETAIL_STAMP_FACET_NAME);
+        //super.processUpdates(context);
+        //if ( facet != null ) getFacets().put(HtmlTableRenderer.DETAIL_STAMP_FACET_NAME,(UIComponent)
facet);
+        
+        setRowIndex(-1);
+        processFacets(context, PROCESS_UPDATES);
+        processColumnFacets(context, PROCESS_UPDATES);
+        processColumnChildren(context, PROCESS_UPDATES);
+        setRowIndex(-1);
 
         processColumns(context, PROCESS_UPDATES);
         setRowIndex(-1);

Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/component/html/ext/HtmlDataTableHack.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/component/html/ext/HtmlDataTableHack.java?rev=991981&r1=991980&r2=991981&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/component/html/ext/HtmlDataTableHack.java
(original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/component/html/ext/HtmlDataTableHack.java
Thu Sep  2 15:30:36 2010
@@ -41,7 +41,6 @@ import javax.faces.model.ResultSetDataMo
 import javax.faces.model.ScalarDataModel;
 import javax.servlet.jsp.jstl.sql.Result;
 
-import org.apache.myfaces.component.ForceIdAware;
 import org.apache.myfaces.component.html.util.HtmlComponentUtils;
 import org.apache.myfaces.custom.ExtendedComponentBase;
 
@@ -329,6 +328,11 @@ public abstract class HtmlDataTableHack 
         }
     }
 
+    protected void restoreDescendantComponentStates(Object state)
+    {
+        restoreDescendantComponentStates(getChildren().iterator(), state, false);
+    }
+
     protected void restoreDescendantComponentStates(Iterator childIterator,
             Object state, boolean restoreChildFacets)
     {
@@ -373,6 +377,11 @@ public abstract class HtmlDataTableHack 
         }
     }
 
+    protected Object saveDescendantComponentStates()
+    {
+        return saveDescendantComponentStates(getChildren().iterator(), false);
+    }
+
     protected Object saveDescendantComponentStates(Iterator childIterator,
             boolean saveChildFacets)
     {

Added: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/component/html/ext/_DetailStampFacetAndChildrenIterator.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/component/html/ext/_DetailStampFacetAndChildrenIterator.java?rev=991981&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/component/html/ext/_DetailStampFacetAndChildrenIterator.java
(added)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/component/html/ext/_DetailStampFacetAndChildrenIterator.java
Thu Sep  2 15:30:36 2010
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.myfaces.component.html.ext;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+
+import javax.faces.component.UIComponent;
+
+/**
+ * @author Leonardo Uribe
+ * @since 1.1.10
+ */
+class _DetailStampFacetAndChildrenIterator implements Iterator
+{
+    private UIComponent _detailStamp;
+    private Iterator _childrenIterator;
+
+    _DetailStampFacetAndChildrenIterator(UIComponent detailStamp, List childrenList)
+    {
+        _detailStamp = detailStamp;
+        _childrenIterator = childrenList != null ? childrenList.iterator() : null;
+    }
+
+    public boolean hasNext()
+    {
+        boolean hasNext = (_detailStamp != null)
+                || (_childrenIterator != null && _childrenIterator.hasNext());
+        if (!hasNext)
+        {
+            _detailStamp = null;
+            _childrenIterator = null;
+        }
+        
+        return hasNext;
+    }
+
+    public Object next()
+    {
+        if (_detailStamp != null)
+        {
+            UIComponent detailStamp = _detailStamp;
+            _detailStamp = null;
+            return detailStamp;
+        }
+        else if (_childrenIterator != null && _childrenIterator.hasNext())
+        {
+            return _childrenIterator.next();
+        }
+        else
+        {
+            throw new NoSuchElementException();
+        }
+    }
+
+    public void remove()
+    {
+        throw new UnsupportedOperationException(this.getClass().getName() + " UnsupportedOperationException");
+    }
+}



Mime
View raw message