myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r1154358 - in /myfaces/core/trunk/api/src/main/java/javax/faces/component: UIComponentBase.java _AttachedCollectionStateWrapper.java
Date Fri, 05 Aug 2011 19:19:34 GMT
Author: lu4242
Date: Fri Aug  5 19:19:34 2011
New Revision: 1154358

URL: http://svn.apache.org/viewvc?rev=1154358&view=rev
Log:
MYFACES-3267 UIComponentBase.saveAttachedState now handles collections instead only lists

Added:
    myfaces/core/trunk/api/src/main/java/javax/faces/component/_AttachedCollectionStateWrapper.java
Modified:
    myfaces/core/trunk/api/src/main/java/javax/faces/component/UIComponentBase.java

Modified: myfaces/core/trunk/api/src/main/java/javax/faces/component/UIComponentBase.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/UIComponentBase.java?rev=1154358&r1=1154357&r2=1154358&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/component/UIComponentBase.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/component/UIComponentBase.java Fri Aug
 5 19:19:34 2011
@@ -1594,19 +1594,33 @@ public abstract class UIComponentBase ex
             }
 
             return new _AttachedStateWrapper(attachedObject.getClass(), holder.saveState(context));
-        }        
-        else if (attachedObject instanceof List)
+        }
+        else if (attachedObject instanceof Collection)
         {
-            List<Object> lst = new ArrayList<Object>(((List<?>) attachedObject).size());
-            for (Object item : (List<?>) attachedObject)
+            if (ArrayList.class.equals(attachedObject.getClass()))
             {
-                if (item != null)
+                List<Object> lst = new ArrayList<Object>(((List<?>) attachedObject).size());
+                for (Object item : (List<?>) attachedObject)
                 {
-                    lst.add(saveAttachedState(context, item));
+                    if (item != null)
+                    {
+                        lst.add(saveAttachedState(context, item));
+                    }
                 }
+                return new _AttachedListStateWrapper(lst);
+            }
+            else
+            {
+                List<Object> lst = new ArrayList<Object>(((Collection<?>)
attachedObject).size());
+                for (Object item : (Collection<?>) attachedObject)
+                {
+                    if (item != null)
+                    {
+                        lst.add(saveAttachedState(context, item));
+                    }
+                }
+                return new _AttachedCollectionStateWrapper(attachedObject.getClass(), lst);
             }
-
-            return new _AttachedListStateWrapper(lst);
         }
         else if (attachedObject instanceof Serializable)
         {
@@ -1634,6 +1648,33 @@ public abstract class UIComponentBase ex
             }
             return restoredList;
         }
+        else if (stateObj instanceof _AttachedCollectionStateWrapper)
+        {
+            _AttachedCollectionStateWrapper wrappedState = (_AttachedCollectionStateWrapper)
stateObj; 
+            Class<?> clazz = wrappedState.getClazz();
+            List<Object> lst = wrappedState.getWrappedStateList();
+            Collection restoredList;
+            try
+            {
+                restoredList = (Collection) clazz.newInstance();
+            }
+            catch (InstantiationException e)
+            {
+                throw new RuntimeException("Could not restore StateHolder of type " + clazz.getName()
+                        + " (missing no-args constructor?)", e);
+            }
+            catch (IllegalAccessException e)
+            {
+                throw new RuntimeException(e);
+            }
+
+            for (Object item : lst)
+            {
+                restoredList.add(restoreAttachedState(context, item));
+            }
+            return restoredList;
+
+        }
         else if (stateObj instanceof _AttachedStateWrapper)
         {
             Class<?> clazz = ((_AttachedStateWrapper) stateObj).getClazz();

Added: myfaces/core/trunk/api/src/main/java/javax/faces/component/_AttachedCollectionStateWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/_AttachedCollectionStateWrapper.java?rev=1154358&view=auto
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/component/_AttachedCollectionStateWrapper.java
(added)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/component/_AttachedCollectionStateWrapper.java
Fri Aug  5 19:19:34 2011
@@ -0,0 +1,49 @@
+/*
+ * 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 javax.faces.component;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * @author Leonardo Uribe
+ */
+class _AttachedCollectionStateWrapper
+        implements Serializable
+{
+    private static final long serialVersionUID = -3958718149793179776L;
+    private Class<?> _class;
+    private List<Object> _wrappedStateList;
+
+    public _AttachedCollectionStateWrapper(Class<?> clazz, List<Object> wrappedStateList)
+    {
+        _class = clazz;
+        _wrappedStateList = wrappedStateList;
+    }
+
+    public Class<?> getClazz()
+    {
+        return _class;
+    }
+
+    public List<Object> getWrappedStateList()
+    {
+        return _wrappedStateList;
+    }
+}



Mime
View raw message