tags:

views:

22

answers:

1

I have been working on stuts app where I'm using an Integer ArrayList. I need to create a dropdown to list the arraylist.

I have been trying using html:select --> html:optioncollection.

But I am getting error of Cannot create iterator for com.SelectTagForm@18488ef.

code:

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

Thanks in advance!!!

+1  A: 

This is the piece of code that is throwing the exception. It's from the optionsCollection tag.

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()));
  }
}

Don't know what your full setup is since you posted only one line of code, but it's obvious that you are not sending it the right collection (you are sending a com.SelectTagForm as the error message specifies).

Read carefully the documentation; and here is a simple tutorial.

One other thing, this tag operates on a collection of beans, where each bean has a label property and a value property (the actual names of these properties can be configured using the label and value attributes of this tag). You can't extract something like that from an Integer ArrayList (as you specified that is your case).

dpb