You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Johan Compagner <jc...@j-com.nl> on 2001/02/07 22:37:09 UTC

OptionsTag comments

Hi,

I want to set the value of a Option.
That value is a integer.

So first i thougth i can just return a int[]
But then i get a class cast exception because the
OptionsTag.getIterater(String,String)
does check if it is a array and then cast it to a Object[] which it isn't.
(Maybe this should be in the doc!)

 if (collection.getClass().isArray())
  collection = Arrays.asList((Object[]) collection);

But then i thought, OK then i make it Integer object array.
But then the OptionsTag.doEndTag() throws a class cast exception because
all the values that are in the iterator are cast to a string!

  while (valuesIterator.hasNext())
  {
   String value = (String) valuesIterator.next();
                        ^^^^^^^^^^
   String label = value;
   if (labelsIterator.hasNext())
    label = (String) labelsIterator.next();
   addOption(sb, value, label, match);
  }

The first thing (it can't be a primitive array, i can live with)
But why must it be a string?
Just do this:
   String value = valuesIterator.next().toString();

If you want it to be a String.

This is because the selected value is also just a int in the Form class.
So why must i myself make it a string?

Johan