【问题标题】:Dropdown for Integer array using html:select使用 html:select 的整数数组的下拉列表
【发布时间】:2010-08-27 09:16:00
【问题描述】:

我一直在使用 Integer ArrayList 开发 stuts 应用程序。我需要创建一个下拉列表来列出数组列表。

我一直在尝试使用 html:select --> html:optioncollection。

但我收到Cannot create iterator for com.SelectTagForm@18488ef 的错误。

代码:

<html:optionsCollection name="selectTagForm" 
label="grade" value="grade" />

提前致谢!!!

【问题讨论】:

    标签: java jsp struts


    【解决方案1】:

    这是引发异常的一段代码。它来自optionsCollection 标签。

    protected Iterator getIterator(Object collection)
      throws JspException {
      if (collection.getClass().isArray()) {
        collection = Arrays.asList((Object[]) collection);
      }
      if (collection instanceof Collection) {
        return (((Collection) collection).iterator());
      } else if (collection instanceof Iterator) {
        return ((Iterator) collection);
      } else if (collection instanceof Map) {
        return (((Map) collection).entrySet().iterator());
      } else if (collection instanceof Enumeration) {
        return new IteratorAdapter((Enumeration) collection);
      } else {
        throw new JspException(messages.getMessage(
            "optionsCollectionTag.iterator", collection.toString()));
      }
    }
    

    不知道您的完整设置是什么,因为您只发布了一行代码,但很明显您没有发送正确的集合(您正在发送com.SelectTagForm,如错误消息所示)。

    仔细阅读the documentation;而here 是一个简单的教程。

    另外,这个标签作用于一个bean的集合,其中每个bean都有一个label属性和一个value属性(这些属性的实际名称可以使用这个标签的labelvalue属性来配置)。您不能从 Integer ArrayList 中提取类似的内容(正如您指定的那样)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-04
      • 2021-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-19
      • 1970-01-01
      相关资源
      最近更新 更多