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 2012/04/18 23:07:36 UTC

svn commit: r1327684 - in /myfaces/tomahawk/trunk: core/src/main/java/org/apache/myfaces/component/html/ext/ core/src/main/java/org/apache/myfaces/custom/datalist/ core12/src/main/java/org/apache/myfaces/custom/datalist/ core20/src/main/java/org/apache...

Author: lu4242
Date: Wed Apr 18 21:07:35 2012
New Revision: 1327684

URL: http://svn.apache.org/viewvc?rev=1327684&view=rev
Log:
TOMAHAWK-1623 facets of components are not included on direct childs of t:dataList

Added:
    myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/custom/datalist/HtmlDataListPreserveRowComponentStateTest.java   (with props)
Modified:
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/component/html/ext/HtmlDataTableHack.java
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/datalist/AbstractHtmlDataList.java
    myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/custom/datalist/AbstractHtmlDataList.java
    myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/datalist/AbstractHtmlDataList.java

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=1327684&r1=1327683&r2=1327684&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 Wed Apr 18 21:07:35 2012
@@ -268,15 +268,13 @@ public abstract class HtmlDataTableHack 
         {
             if (_initialDescendantComponentState == null)
             {
-                _initialDescendantComponentState = saveDescendantComponentStates(getChildren()
-                                .iterator(), false);
+                _initialDescendantComponentState = saveDescendantComponentStates();
             }
         }
         else
         {
             _rowStates.put(getClientId(facesContext),
-                            saveDescendantComponentStates(getChildren()
-                                            .iterator(), false));
+                            saveDescendantComponentStates());
         }
 
         _rowIndex = rowIndex;
@@ -312,21 +310,18 @@ public abstract class HtmlDataTableHack 
 
         if (_rowIndex == -1)
         {
-            restoreDescendantComponentStates(getChildren().iterator(),
-                            _initialDescendantComponentState, false);
+            restoreDescendantComponentStates(_initialDescendantComponentState);
         }
         else
         {
             Object rowState = _rowStates.get(getClientId(facesContext));
             if (rowState == null)
             {
-                restoreDescendantComponentStates(getChildren().iterator(),
-                                _initialDescendantComponentState, false);
+                restoreDescendantComponentStates(_initialDescendantComponentState);
             }
             else
             {
-                restoreDescendantComponentStates(getChildren().iterator(),
-                                rowState, false);
+                restoreDescendantComponentStates(rowState);
             }
         }
     }

Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/datalist/AbstractHtmlDataList.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/datalist/AbstractHtmlDataList.java?rev=1327684&r1=1327683&r2=1327684&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/datalist/AbstractHtmlDataList.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/datalist/AbstractHtmlDataList.java Wed Apr 18 21:07:35 2012
@@ -205,7 +205,19 @@ public abstract class AbstractHtmlDataLi
             }
         }
     }
-    
+
+    @Override
+    protected void restoreDescendantComponentStates(Object state)
+    {
+        restoreDescendantComponentStates(getChildren().iterator(), state, true);
+    }
+
+    @Override
+    protected Object saveDescendantComponentStates()
+    {
+        return saveDescendantComponentStates(getChildren().iterator(), true);
+    }
+
     /**
      * A parameter name, under which the rowCount is set in request 
      * scope similar to the var parameter.

Modified: myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/custom/datalist/AbstractHtmlDataList.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/custom/datalist/AbstractHtmlDataList.java?rev=1327684&r1=1327683&r2=1327684&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/custom/datalist/AbstractHtmlDataList.java (original)
+++ myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/custom/datalist/AbstractHtmlDataList.java Wed Apr 18 21:07:35 2012
@@ -211,6 +211,18 @@ public abstract class AbstractHtmlDataLi
             }
         }
     }
+    
+    @Override
+    protected void restoreDescendantComponentStates(Object state)
+    {
+        restoreDescendantComponentStates(getChildren().iterator(), state, true);
+    }
+    
+    @Override
+    protected Object saveDescendantComponentStates()
+    {
+        return saveDescendantComponentStates(getChildren().iterator(), true);
+    }
 
     @Override
     public boolean invokeOnComponent(FacesContext context, String clientId, ContextCallback callback)

Modified: myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/datalist/AbstractHtmlDataList.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/datalist/AbstractHtmlDataList.java?rev=1327684&r1=1327683&r2=1327684&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/datalist/AbstractHtmlDataList.java (original)
+++ myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/datalist/AbstractHtmlDataList.java Wed Apr 18 21:07:35 2012
@@ -218,6 +218,43 @@ public abstract class AbstractHtmlDataLi
     }
     
     @Override
+    protected void restoreDescendantComponentStates(Object state)
+    {
+        restoreDescendantComponentStates(getChildren().iterator(), state, true);
+    }
+
+    @Override
+    protected Object saveDescendantComponentStates()
+    {
+        return saveDescendantComponentStates(getChildren().iterator(), true);
+    }
+    
+    @Override
+    protected Map<String,Object> saveFullDescendantComponentStates(FacesContext facesContext)
+    {
+        return saveFullDescendantComponentStates(facesContext, null, getChildren().iterator(), true, getContainerClientId(facesContext));
+    }
+    
+    @Override
+    protected void restoreFullDescendantComponentStates(FacesContext facesContext, Object initialState)
+    {
+        restoreFullDescendantComponentStates(facesContext, getChildren().iterator(), initialState, true);
+    }
+
+    @Override
+    protected void restoreFullDescendantComponentDeltaStates(FacesContext facesContext,
+            Map<String, Object> rowState, Object initialState)
+    {
+        restoreFullDescendantComponentDeltaStates(facesContext, getChildren().iterator(), rowState, initialState, true, getContainerClientId(facesContext));
+    }
+    
+    @Override
+    protected Collection<Object[]> saveDescendantInitialComponentStates(FacesContext facesContext)
+    {
+        return saveDescendantInitialComponentStates(facesContext, getChildren().iterator(), true);
+    }
+
+    @Override
     public boolean invokeOnComponent(FacesContext context, String clientId, ContextCallback callback)
         throws FacesException
     {

Added: myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/custom/datalist/HtmlDataListPreserveRowComponentStateTest.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/custom/datalist/HtmlDataListPreserveRowComponentStateTest.java?rev=1327684&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/custom/datalist/HtmlDataListPreserveRowComponentStateTest.java (added)
+++ myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/custom/datalist/HtmlDataListPreserveRowComponentStateTest.java Wed Apr 18 21:07:35 2012
@@ -0,0 +1,352 @@
+/*
+ * 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.custom.datalist;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.faces.component.ContextCallback;
+import javax.faces.component.UIColumn;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIOutput;
+import javax.faces.component.UIPanel;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+
+import junit.framework.Assert;
+
+import org.apache.myfaces.test.base.AbstractJsfTestCase;
+import org.apache.myfaces.test.utils.TestUtils;
+
+public class HtmlDataListPreserveRowComponentStateTest extends AbstractJsfTestCase
+{
+
+    public HtmlDataListPreserveRowComponentStateTest(String name)
+    {
+        super(name);
+    }
+    
+    @Override
+    protected void setUpRenderKit() throws Exception
+    {
+        super.setUpRenderKit();
+        TestUtils.addDefaultRenderers(facesContext);
+    }
+
+    public static class RowData
+    {
+        private String text;
+
+        public RowData(String text, String style)
+        {
+            super();
+            this.text = text;
+            this.style = style;
+        }
+
+        private String style;
+        
+        public String getText()
+        {
+            return text;
+        }
+
+        public void setText(String text)
+        {
+            this.text = text;
+        }
+
+        public String getStyle()
+        {
+            return style;
+        }
+
+        public void setStyle(String style)
+        {
+            this.style = style;
+        }
+    }
+    
+    public void testPreserveRowComponentState1() throws Exception
+    {
+        List<RowData> model = new ArrayList<RowData>();
+        model.add(new RowData("text1","style1"));
+        model.add(new RowData("text1","style2"));
+        model.add(new RowData("text1","style3"));
+        model.add(new RowData("text1","style4"));
+        
+        //Put on request map to be resolved later
+        request.setAttribute("list", model);
+        
+        UIViewRoot root = facesContext.getViewRoot();
+        HtmlDataList table = new HtmlDataList();
+        //UIColumn column = new UIColumn();
+        UIOutput text = new UIOutput();
+        
+        //This is only required if markInitiaState fix is not used 
+        root.setId("root");
+        table.setId("table");
+        //column.setId("column");
+        text.setId("text");
+        
+        table.setVar("row");
+        table.setPreserveRowComponentState(true);
+        table.setValueExpression("value", application.
+                getExpressionFactory().createValueExpression(
+                        facesContext.getELContext(),"#{list}",List.class));
+        
+        text.setValueExpression("value", application.
+                getExpressionFactory().createValueExpression(
+                        facesContext.getELContext(),"#{row.text}",String.class));
+        
+        root.getChildren().add(table);
+        //table.getChildren().add(column);
+        //column.getChildren().add(text);
+        table.getChildren().add(text);
+
+        //Simulate markInitialState call.
+        facesContext.getAttributes().put("javax.faces.view.ViewDeclarationLanguage.IS_BUILDING_INITIAL_STATE", Boolean.TRUE);
+        root.markInitialState();
+        table.markInitialState();
+        //column.markInitialState();
+        text.markInitialState();
+        facesContext.getAttributes().remove("javax.faces.view.ViewDeclarationLanguage.IS_BUILDING_INITIAL_STATE");
+        
+        //Check the value expressions are working and change the component state 
+        for (int i = 0; i < model.size(); i++)
+        {
+            RowData rowData = model.get(i); 
+            table.setRowIndex(i);
+            assertEquals(rowData.getText(), text.getValue());
+            text.getAttributes().put("style", rowData.getStyle());
+        }
+        
+        //Reset row index
+        table.setRowIndex(-1);
+
+        //Check the values were not lost
+        for (int i = 0; i < model.size(); i++)
+        {
+            table.setRowIndex(i);
+            assertEquals(model.get(i).getStyle(), text.getAttributes().get("style"));
+        }
+        
+    }
+    
+    public void testPreserveRowComponentState1Facet() throws Exception
+    {
+        List<RowData> model = new ArrayList<RowData>();
+        model.add(new RowData("text1","style1"));
+        model.add(new RowData("text1","style2"));
+        model.add(new RowData("text1","style3"));
+        model.add(new RowData("text1","style4"));
+        
+        //Put on request map to be resolved later
+        request.setAttribute("list", model);
+        
+        UIViewRoot root = facesContext.getViewRoot();
+        HtmlDataList table = new HtmlDataList();
+        UIPanel panel = new UIPanel();
+        UIOutput text = new UIOutput();
+        
+        //This is only required if markInitiaState fix is not used 
+        root.setId("root");
+        table.setId("table");
+        panel.setId("column");
+        text.setId("text");
+        
+        table.setVar("row");
+        table.setPreserveRowComponentState(true);
+        table.setValueExpression("value", application.
+                getExpressionFactory().createValueExpression(
+                        facesContext.getELContext(),"#{list}",List.class));
+        
+        text.setValueExpression("value", application.
+                getExpressionFactory().createValueExpression(
+                        facesContext.getELContext(),"#{row.text}",String.class));
+        
+        root.getChildren().add(table);
+        table.getChildren().add(panel);
+        panel.getFacets().put(UIComponent.COMPOSITE_FACET_NAME, text);
+
+        //Simulate markInitialState call.
+        facesContext.getAttributes().put("javax.faces.view.ViewDeclarationLanguage.IS_BUILDING_INITIAL_STATE", Boolean.TRUE);
+        root.markInitialState();
+        table.markInitialState();
+        panel.markInitialState();
+        text.markInitialState();
+        facesContext.getAttributes().remove("javax.faces.view.ViewDeclarationLanguage.IS_BUILDING_INITIAL_STATE");
+        
+        //Check the value expressions are working and change the component state 
+        for (int i = 0; i < model.size(); i++)
+        {
+            RowData rowData = model.get(i); 
+            table.setRowIndex(i);
+            assertEquals(rowData.getText(), text.getValue());
+            text.getAttributes().put("style", rowData.getStyle());
+        }
+        
+        //Reset row index
+        table.setRowIndex(-1);
+
+        //Check the values were not lost
+        for (int i = 0; i < model.size(); i++)
+        {
+            table.setRowIndex(i);
+            assertEquals(model.get(i).getText(), text.getAttributes().get("value"));
+            assertEquals(model.get(i).getStyle(), text.getAttributes().get("style"));
+        }
+        
+    }
+    
+    public void testState1Facet() throws Exception
+    {
+        List<RowData> model = new ArrayList<RowData>();
+        model.add(new RowData("text1","style1"));
+        model.add(new RowData("text1","style2"));
+        model.add(new RowData("text1","style3"));
+        model.add(new RowData("text1","style4"));
+        
+        //Put on request map to be resolved later
+        request.setAttribute("list", model);
+        
+        UIViewRoot root = facesContext.getViewRoot();
+        HtmlDataList table = new HtmlDataList();
+        UIPanel panel = new UIPanel();
+        UIOutput text = new UIOutput();
+        
+        //This is only required if markInitiaState fix is not used 
+        root.setId("root");
+        table.setId("table");
+        panel.setId("column");
+        text.setId("text");
+        
+        table.setVar("row");
+        //table.setPreserveRowComponentState(true);
+        table.setValueExpression("value", application.
+                getExpressionFactory().createValueExpression(
+                        facesContext.getELContext(),"#{list}",List.class));
+        
+        text.setValueExpression("value", application.
+                getExpressionFactory().createValueExpression(
+                        facesContext.getELContext(),"#{row.text}",String.class));
+        
+        root.getChildren().add(table);
+        table.getChildren().add(panel);
+        panel.getFacets().put(UIComponent.COMPOSITE_FACET_NAME, text);
+
+        //Simulate markInitialState call.
+        facesContext.getAttributes().put("javax.faces.view.ViewDeclarationLanguage.IS_BUILDING_INITIAL_STATE", Boolean.TRUE);
+        root.markInitialState();
+        table.markInitialState();
+        panel.markInitialState();
+        text.markInitialState();
+        facesContext.getAttributes().remove("javax.faces.view.ViewDeclarationLanguage.IS_BUILDING_INITIAL_STATE");
+        
+        //Check the value expressions are working and change the component state 
+        for (int i = 0; i < model.size(); i++)
+        {
+            RowData rowData = model.get(i); 
+            table.setRowIndex(i);
+            assertEquals(rowData.getText(), text.getValue());
+            text.getAttributes().put("style", rowData.getStyle());
+        }
+        
+        //Reset row index
+        table.setRowIndex(-1);
+
+        //Check the values were not lost
+        for (int i = 0; i < model.size(); i++)
+        {
+            table.setRowIndex(i);
+            assertEquals(model.get(i).getText(), text.getAttributes().get("value"));
+        }
+        
+    }
+    
+    public void testPreserveRowComponentState2() throws Exception
+    {
+        List<RowData> model = new ArrayList<RowData>();
+        model.add(new RowData("text1","style1"));
+        model.add(new RowData("text1","style2"));
+        model.add(new RowData("text1","style3"));
+        model.add(new RowData("text1","style4"));
+        
+        //Put on request map to be resolved later
+        request.setAttribute("list", model);
+        
+        UIViewRoot root = facesContext.getViewRoot();
+        HtmlDataList table = new HtmlDataList();
+        UIPanel column = new UIPanel();
+        UIOutput text = new UIOutput();
+        
+        //This is only required if markInitiaState fix is not used 
+        root.setId("root");
+        table.setId("table");
+        column.setId("column");
+        text.setId("text");
+        
+        table.setVar("row");
+        table.setPreserveRowComponentState(true);
+        table.setValueExpression("value", application.
+                getExpressionFactory().createValueExpression(
+                        facesContext.getELContext(),"#{list}",List.class));
+        
+        text.setValueExpression("value", application.
+                getExpressionFactory().createValueExpression(
+                        facesContext.getELContext(),"#{row.text}",String.class));
+        
+        root.getChildren().add(table);
+        table.getChildren().add(column);
+        column.getFacets().put(UIComponent.COMPOSITE_FACET_NAME, text);
+
+        //Simulate markInitialState call.
+        facesContext.getAttributes().put("javax.faces.view.ViewDeclarationLanguage.IS_BUILDING_INITIAL_STATE", Boolean.TRUE);
+        root.markInitialState();
+        table.markInitialState();
+        column.markInitialState();
+        text.markInitialState();
+        facesContext.getAttributes().remove("javax.faces.view.ViewDeclarationLanguage.IS_BUILDING_INITIAL_STATE");
+        
+        //Check the value expressions are working and change the component state 
+        for (int i = 0; i < model.size(); i++)
+        {
+            RowData rowData = model.get(i); 
+            table.setRowIndex(i);
+            assertEquals(rowData.getText(), text.getValue());
+            text.getAttributes().put("style", rowData.getStyle());
+        }
+        
+        //Reset row index
+        table.setRowIndex(-1);
+
+        //Remove a row
+        table.deleteRowStateForRow(1);
+        model.remove(1);
+
+        //Check the values were not lost
+        for (int i = 0; i < model.size(); i++)
+        {
+            table.setRowIndex(i);
+            assertEquals(model.get(i).getStyle(), text.getAttributes().get("style"));
+        }
+        
+    }
+
+}

Propchange: myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/custom/datalist/HtmlDataListPreserveRowComponentStateTest.java
------------------------------------------------------------------------------
    svn:eol-style = native