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 2013/04/23 00:45:45 UTC

svn commit: r1470740 - /myfaces/core/branches/2.1.x/api/src/main/java/javax/faces/component/UISelectOne.java

Author: lu4242
Date: Mon Apr 22 22:45:45 2013
New Revision: 1470740

URL: http://svn.apache.org/r1470740
Log:
MYFACES-3710 Create SelectItemsIterator only once in UISelectOne.validateValue() (thanks to Dennis Hoersch for provide this patch)

Modified:
    myfaces/core/branches/2.1.x/api/src/main/java/javax/faces/component/UISelectOne.java

Modified: myfaces/core/branches/2.1.x/api/src/main/java/javax/faces/component/UISelectOne.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.1.x/api/src/main/java/javax/faces/component/UISelectOne.java?rev=1470740&r1=1470739&r2=1470740&view=diff
==============================================================================
--- myfaces/core/branches/2.1.x/api/src/main/java/javax/faces/component/UISelectOne.java (original)
+++ myfaces/core/branches/2.1.x/api/src/main/java/javax/faces/component/UISelectOne.java Mon Apr 22 22:45:45 2013
@@ -18,8 +18,12 @@
  */
 package javax.faces.component;
 
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
 import javax.faces.context.FacesContext;
 import javax.faces.convert.Converter;
+import javax.faces.model.SelectItem;
 
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFComponent;
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFJspProperty;
@@ -75,14 +79,21 @@ public class UISelectOne extends UIInput
         // and if required is true it must not match an option with noSelectionOption set to true (since 2.0)
         Converter converter = getConverter();
 
-        if (_SelectItemsUtil.matchValue(context, this, value, new _SelectItemsIterator(this, context), converter))
+        // Since the iterator is used twice, it has sense to traverse it only once.
+        Collection<SelectItem> items = new ArrayList<SelectItem>();
+        for (Iterator<SelectItem> iter = new _SelectItemsIterator(this, context); iter.hasNext();)
+        {
+            items.add(iter.next());
+        }
+        
+        if (_SelectItemsUtil.matchValue(context, this, value, items.iterator(), converter))
         {
             if (! this.isRequired())
             {
                 return; // Matched & Required false, so return ok.
             }
             if (! _SelectItemsUtil.isNoSelectionOption(context, this, value, 
-                    new _SelectItemsIterator(this, context), converter))
+                    items.iterator(), converter))
             {
                 return; // Matched & Required true & No-selection did NOT match, so return ok.
             }