You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2014/02/26 10:42:04 UTC

svn commit: r1571979 - /myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/RenderUtils.java

Author: lofwyr
Date: Wed Feb 26 09:42:03 2014
New Revision: 1571979

URL: http://svn.apache.org/r1571979
Log:
TOBAGO-1362: Support dynamic list of objects for f:selectItems
- clean up

Modified:
    myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/RenderUtils.java

Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/RenderUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/RenderUtils.java?rev=1571979&r1=1571978&r2=1571979&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/RenderUtils.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/RenderUtils.java Wed Feb 26 09:42:03 2014
@@ -33,7 +33,6 @@ import org.apache.myfaces.tobago.renderk
 import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
 import org.apache.myfaces.tobago.renderkit.html.HtmlInputTypes;
 import org.apache.myfaces.tobago.util.ComponentUtils;
-import org.apache.myfaces.tobago.util.DebugUtils;
 import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -43,32 +42,19 @@ import javax.faces.application.ViewHandl
 import javax.faces.component.EditableValueHolder;
 import javax.faces.component.UIComponent;
 import javax.faces.component.UIParameter;
-import javax.faces.component.UISelectItem;
-import javax.faces.component.UISelectItems;
 import javax.faces.component.ValueHolder;
 import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
 import javax.faces.convert.Converter;
 import javax.faces.convert.ConverterException;
-import javax.faces.model.SelectItem;
 import java.io.IOException;
 import java.net.URLDecoder;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
 import java.util.List;
-import java.util.Map;
 
 public class RenderUtils {
 
   private static final Logger LOG = LoggerFactory.getLogger(RenderUtils.class);
 
-  /**
-   * @deprecated since 2.0.0
-   */
-  @Deprecated
-  public static final String COMPONENT_IN_REQUEST = "org.apache.myfaces.tobago.component";
-
   public static final String SCROLL_POSTFIX = ComponentUtils.SUB_SEPARATOR + "scrollPosition";
 
   private RenderUtils() {
@@ -221,54 +207,6 @@ public class RenderUtils {
     return Measure.valueOf(width);
   }
 
-  /**
-   * @deprecated Since Tobago 2.0.0. Please use SelectItemUtils
-   */
-  @Deprecated
-  public static List<SelectItem> getItemsToRender(final javax.faces.component.UISelectOne component) {
-    return getItems(component);
-  }
-
-  /**
-   * @deprecated Since Tobago 2.0.0. Please use SelectItemUtils
-   */
-  @Deprecated
-  public static List<SelectItem> getItemsToRender(final javax.faces.component.UISelectMany component) {
-    return getItems(component);
-  }
-
-  /**
-   * @deprecated Since Tobago 2.0.0. Please use SelectItemUtils
-   */
-  @Deprecated
-  public static List<SelectItem> getItems(final javax.faces.component.UIInput component) {
-
-    final List<SelectItem> selectItems = getSelectItems(component);
-
-    String renderRange = (String) component.getAttributes().get(Attributes.RENDER_RANGE_EXTERN);
-    if (renderRange == null) {
-      renderRange = (String) component.getAttributes().get(Attributes.RENDER_RANGE);
-    }
-    if (renderRange == null) {
-      return selectItems;
-    }
-
-    final int[] indices = StringUtils.getIndices(renderRange);
-    final List<SelectItem> items = new ArrayList<SelectItem>(indices.length);
-
-    if (selectItems.size() != 0) {
-      for (final int index : indices) {
-        items.add(selectItems.get(index));
-      }
-    } else {
-      LOG.warn("No items found! rendering dummies instead!");
-      for (int i = 0; i < indices.length; i++) {
-        items.add(new SelectItem(Integer.toString(i), "Item " + i, ""));
-      }
-    }
-    return items;
-  }
-
   public static String currentValue(final UIComponent component) {
     String currentValue = null;
     if (component instanceof ValueHolder) {
@@ -299,95 +237,6 @@ public class RenderUtils {
     return currentValue;
   }
 
-  /**
-   * @deprecated Since Tobago 2.0.0. Please use SelectItemUtils
-   */
-  @Deprecated
-  public static List<SelectItem> getSelectItems(final UIComponent component) {
-
-    final ArrayList<SelectItem> list = new ArrayList<SelectItem>();
-
-    for (final UIComponent child : component.getChildren()) {
-      if (LOG.isDebugEnabled()) {
-        LOG.debug("kid " + child);
-        LOG.debug("kid " + child.getClass().getName());
-      }
-      if (child instanceof UISelectItem) {
-        final Object value = ((UISelectItem) child).getValue();
-        if (value == null) {
-          final UISelectItem item = (UISelectItem) child;
-          if (child instanceof org.apache.myfaces.tobago.component.UISelectItem) {
-            list.add(getSelectItem(
-                (org.apache.myfaces.tobago.component.UISelectItem) child));
-          } else {
-            list.add(new SelectItem(item.getItemValue() == null ? "" : item.getItemValue(),
-                item.getItemLabel() != null ? item.getItemLabel() : item.getItemValue().toString(),
-                item.getItemDescription()));
-          }
-        } else if (value instanceof SelectItem) {
-          list.add((SelectItem) value);
-        } else {
-          final String message
-              = "TYPE ERROR: value NOT instanceof SelectItem. type="
-              + value.getClass().getName() + " value=" + value;
-          LOG.error(message);
-          DebugUtils.addDevelopmentMessage(FacesContext.getCurrentInstance(), message);
-        }
-      } else if (child instanceof UISelectItems) {
-        final Object value = ((UISelectItems) child).getValue();
-        if (LOG.isDebugEnabled()) {
-          LOG.debug("value " + value);
-          if (value != null) {
-            LOG.debug("value " + value.getClass().getName());
-          }
-        }
-        if (value == null) {
-          if (LOG.isDebugEnabled()) {
-            LOG.debug("value is null");
-          }
-        } else if (value instanceof SelectItem) {
-          list.add((SelectItem) value);
-        } else if (value instanceof SelectItem[]) {
-          final SelectItem[] items = (SelectItem[]) value;
-          list.addAll(Arrays.asList(items));
-        } else if (value instanceof Collection) {
-          for (final Object o : ((Collection) value)) {
-            list.add((SelectItem) o);
-          }
-        } else if (value instanceof Map) {
-          for (final Object key : ((Map) value).keySet()) {
-            if (key != null) {
-              final Object val = ((Map) value).get(key);
-              if (val != null) {
-                list.add(new SelectItem(val.toString(), key.toString(), null));
-              }
-            }
-          }
-        } else {
-          final String message
-              = "TYPE ERROR: value NOT instanceof SelectItem, SelectItem[], Collection, Map. type="
-              + value.getClass().getName() + " value=" + value;
-          LOG.error(message);
-          DebugUtils.addDevelopmentMessage(FacesContext.getCurrentInstance(), message);
-        }
-      }
-    }
-
-    return list;
-  }
-
-  /**
-   * @deprecated Since Tobago 2.0.0. Please use SelectItemUtils
-   */
-  @Deprecated
-  private static SelectItem getSelectItem(final org.apache.myfaces.tobago.component.UISelectItem component) {
-    return
-        new org.apache.myfaces.tobago.model.SelectItem(component.getItemValue() == null ? "" : component.getItemValue(),
-            component.getItemLabel(), component.getItemDescription(),
-            component.isItemDisabled(), component.getItemImage(), component.getMarkup());
-  }
-
-
   public static void decodedStateOfTreeData(final FacesContext facesContext, final AbstractUIData data) {
 
     if (!data.isTreeModel()) {