You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mb...@apache.org on 2005/09/02 16:20:35 UTC
svn commit: r267208 - in /myfaces/api/trunk/src/java/javax/faces/component:
UISelectOne.java _SelectItemsIterator.java
Author: mbr
Date: Fri Sep 2 07:20:32 2005
New Revision: 267208
URL: http://svn.apache.org/viewcvs?rev=267208&view=rev
Log:
quick fix to make HEAD compile
Added:
myfaces/api/trunk/src/java/javax/faces/component/_SelectItemsIterator.java (with props)
Modified:
myfaces/api/trunk/src/java/javax/faces/component/UISelectOne.java
Modified: myfaces/api/trunk/src/java/javax/faces/component/UISelectOne.java
URL: http://svn.apache.org/viewcvs/myfaces/api/trunk/src/java/javax/faces/component/UISelectOne.java?rev=267208&r1=267207&r2=267208&view=diff
==============================================================================
--- myfaces/api/trunk/src/java/javax/faces/component/UISelectOne.java (original)
+++ myfaces/api/trunk/src/java/javax/faces/component/UISelectOne.java Fri Sep 2 07:20:32 2005
@@ -22,8 +22,6 @@
import javax.faces.model.SelectItem;
import javax.faces.model.SelectItemGroup;
-import org.apache.myfaces.util.SelectItemsIterator;
-
/**
* see Javadoc of JSF Specification
*
@@ -47,7 +45,7 @@
}
// selected value must match to one of the available options
- if (!matchValue(context, value, new SelectItemsIterator(this)))
+ if (!matchValue(context, value, new _SelectItemsIterator(this)))
{
_MessageUtils.addErrorMessage(context, this, INVALID_MESSAGE_ID,
new Object[] {getId()});
Added: myfaces/api/trunk/src/java/javax/faces/component/_SelectItemsIterator.java
URL: http://svn.apache.org/viewcvs/myfaces/api/trunk/src/java/javax/faces/component/_SelectItemsIterator.java?rev=267208&view=auto
==============================================================================
--- myfaces/api/trunk/src/java/javax/faces/component/_SelectItemsIterator.java (added)
+++ myfaces/api/trunk/src/java/javax/faces/component/_SelectItemsIterator.java Fri Sep 2 07:20:32 2005
@@ -0,0 +1,187 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UISelectItem;
+import javax.faces.component.UISelectItems;
+import javax.faces.el.ValueBinding;
+import javax.faces.model.SelectItem;
+
+import org.apache.myfaces.renderkit.RendererUtils;
+
+/**
+ * @author Mathias Broekelmann (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+class _SelectItemsIterator implements Iterator
+{
+ private final Iterator _childs;
+ private Iterator _nestedItems;
+ private UISelectItems _currentUISelectItems;
+ private String _collectionLabel;
+
+ public _SelectItemsIterator(UIComponent selectItemsParent)
+ {
+ _childs = selectItemsParent.getChildren().iterator();
+ }
+
+ public boolean hasNext()
+ {
+ if (_nestedItems != null)
+ {
+ if (_nestedItems.hasNext())
+ {
+ return true;
+ }
+ _nestedItems = null;
+ _currentUISelectItems = null;
+ }
+ return _childs.hasNext();
+ }
+
+ public Object next()
+ {
+ if (!hasNext())
+ {
+ throw new NoSuchElementException();
+ }
+ if (_nestedItems != null)
+ {
+ Object item = _nestedItems.next();
+ if (!(item instanceof SelectItem))
+ {
+ ValueBinding binding = _currentUISelectItems
+ .getValueBinding("value");
+ throw new IllegalArgumentException(
+ _collectionLabel + " referenced by UISelectItems with binding '"
+ + binding.getExpressionString()
+ + "' and Component-Path : " + RendererUtils.getPathToComponent(_currentUISelectItems)
+ + " does not contain Objects of type SelectItem");
+ }
+ return _nestedItems.next();
+ }
+ else if (_childs.hasNext())
+ {
+ UIComponent child = (UIComponent) _childs.next();
+ if (child instanceof UISelectItem)
+ {
+ UISelectItem uiSelectItem = (UISelectItem) child;
+ Object item = uiSelectItem.getValue();
+ if (item == null)
+ {
+ Object itemValue = ((UISelectItem) child).getItemValue();
+ String label = ((UISelectItem) child).getItemLabel();
+ String description = ((UISelectItem) child)
+ .getItemDescription();
+ boolean disabled = ((UISelectItem) child).isItemDisabled();
+ if (label == null)
+ {
+ return new SelectItem(itemValue, itemValue.toString(),
+ description, disabled);
+ }
+ return new SelectItem(itemValue, label, description,
+ disabled);
+ }
+ else if (!(item instanceof SelectItem))
+ {
+ ValueBinding binding = ((UISelectItem) child)
+ .getValueBinding("value");
+ throw new IllegalArgumentException(
+ "Value binding '"
+ + (binding == null ? null : binding.getExpressionString())
+ + "' of UISelectItem : "
+ + RendererUtils.getPathToComponent(child)
+ + " does not reference an Object of type SelectItem");
+ }
+ return item;
+ }
+ else if (child instanceof UISelectItems)
+ {
+ _currentUISelectItems = ((UISelectItems) child);
+
+ Object value = _currentUISelectItems.getValue();
+
+ if (value instanceof SelectItem)
+ {
+ return value;
+ }
+ else if (value instanceof SelectItem[])
+ {
+ _nestedItems = Arrays.asList((SelectItem[]) value)
+ .iterator();
+ _collectionLabel = "Array";
+ return next();
+ }
+ else if (value instanceof Collection)
+ {
+ _nestedItems = ((Collection)value).iterator();
+ _collectionLabel = "Collection";
+ return next();
+ }
+ else if (value instanceof Map)
+ {
+ Map map = ((Map) value);
+ Collection items = new ArrayList(map.size());
+ for (Iterator it = map.entrySet().iterator(); it
+ .hasNext();)
+ {
+ Map.Entry entry = (Map.Entry) it.next();
+ items.add(new SelectItem(entry.getValue(), entry
+ .getKey().toString()));
+ }
+ _nestedItems = items.iterator();
+ _collectionLabel = null;
+ return next();
+ }
+ else
+ {
+ ValueBinding binding = _currentUISelectItems.getValueBinding("value");
+
+ throw new IllegalArgumentException(
+ "Value binding '"
+ + (binding == null ? null : binding
+ .getExpressionString())
+ + "'of UISelectItems with component-path "
+ + RendererUtils.getPathToComponent(child)
+ + " does not reference an Object of type SelectItem, SelectItem[], Collection or Map but of type : "
+ + ((value == null) ? null : value
+ .getClass()
+ .getName()));
+ }
+ }
+ else
+ {
+ //todo: may other objects than selectItems be nested or not?
+ //log.error("Invalid component : " + getPathToComponent(child) + " : must be UISelectItem or UISelectItems, is of type : "+((child==null)?"null":child.getClass().getName()));
+ }
+ }
+ return null;
+ }
+
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+}
Propchange: myfaces/api/trunk/src/java/javax/faces/component/_SelectItemsIterator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/api/trunk/src/java/javax/faces/component/_SelectItemsIterator.java
------------------------------------------------------------------------------
svn:keywords = Id Author Revision Date