You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2010/09/02 17:30:54 UTC

svn commit: r991982 - /myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/component/html/ext/AbstractHtmlDataTable.java

Author: lu4242
Date: Thu Sep  2 15:30:53 2010
New Revision: 991982

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

Modified:
    myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/component/html/ext/AbstractHtmlDataTable.java

Modified: myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/component/html/ext/AbstractHtmlDataTable.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/component/html/ext/AbstractHtmlDataTable.java?rev=991982&r1=991981&r2=991982&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/component/html/ext/AbstractHtmlDataTable.java (original)
+++ myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/component/html/ext/AbstractHtmlDataTable.java Thu Sep  2 15:30:53 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.FacesException;
@@ -125,7 +123,7 @@ public abstract class AbstractHtmlDataTa
 
     private Map _expandedNodes = new HashMap();
 
-    private Map _detailRowStates = new HashMap();
+    //private Map _detailRowStates = new HashMap();
 
     private TableContext _tableContext = null;
 
@@ -333,21 +331,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();
@@ -410,14 +408,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)
         {
@@ -426,6 +424,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())
@@ -436,9 +461,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);
@@ -446,6 +485,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
@@ -508,14 +642,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));
+                //}
             }
         }
     }
@@ -574,9 +713,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);
@@ -599,9 +743,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);