Grails

ClassCastException when list in select uses integer as key

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 0.5
  • Fix Version/s: 0.6-RC1
  • Component/s: None
  • Labels:
    None

Description

I got an exception using the select tag. In my case the key in the list key is an integer (accessed with optionKey="id" ). If the current id is given in the value attribute of the tag, I get an exception. The exception is described in GROOVY-1872 .

The reason seems to be, that the conversion of the integer to the string did not work. So I figured out the following workaround: Convert the keyValue of the listexplicitly into a string. So in FormTagLib.groovy line 513 I changed:
if(keyValue == value) { out << 'selected="selected" ' }
to:
if(keyValue.toString() == value) { out << 'selected="selected" ' } }

Now it works as expected. Not sure if that is the best place for the workaround. The best, of course, would be to fix groovy.

Activity

Hide
Gerd Boerrigter added a comment -

Actually, it does not work as expected. Now I got the same exception in another select tag on a different GSP. Just now it seem, that the value attribute is an integer...
I now made the workaround even more ugly:
if(keyValue?.toString() == value?.toString())
with "?." just to avoid any problems with null.

Show
Gerd Boerrigter added a comment - Actually, it does not work as expected. Now I got the same exception in another select tag on a different GSP. Just now it seem, that the value attribute is an integer... I now made the workaround even more ugly: if(keyValue?.toString() == value?.toString()) with "?." just to avoid any problems with null.
Hide
Lee Butts added a comment -

Suggested fix applied.

Show
Lee Butts added a comment - Suggested fix applied.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: