I want to present a selection of Integers for the user
to choose.  The jsp code is:

      <html:select property="beginYear">
        <html:options property="years"/>
      </html:select>

The form bean has an indexed property "years":
        public Integer [] getYears();

The above jsp code fails with this message:

   Root cause: 
     java.lang.ClassCastException: java.lang.Integer
          at
org.apache.struts.taglib.html.OptionsTag.doEndTag(OptionsTag.java:240)

when org.apache.struts.taglib/html.OptionsTab.doEndTag tries a direct
cast of Integer to String.

I understand that the "beginYear" property must be settable from a
String, but
it seems that the options tag should be able to call toString when
needed to
display properties (to simplify incorporating existing beans into
struts).
I believe html:options does do toString when the "collection" attribute
is specified.

The following short fix to OptionsTag does the trick.  

Am I right that this is a bug/shortcoming with html:options, or is there
a simple 
way around it (logic:iterator?) ?


--- OptionsTag.orig     Sat Feb 24 11:36:21 2001
+++ OptionsTag.java     Tue Mar  6 14:19:43 2001
@@ -237,10 +237,10 @@
 
               // Render the options tags for each element of the values
coll.
               while (valuesIterator.hasNext()) {
-                  String value = (String) valuesIterator.next();
+                  String value = valuesIterator.next().toString();
                   String label = value;
                   if (labelsIterator.hasNext())
-                      label = (String) labelsIterator.next();
+                      label = (String)
labelsIterator.next().toString();
                   addOption(sb, value, label,
                             selectTag.isMatched(value));
               }





-- 
*****************************************************
Gordon Maclean, Software Engineer
http://www.atd.ucar.edu/homes/maclean
Nat'l Center for Atmospheric Research, Boulder CO USA
*****************************************************

Reply via email to