Tuesday, July 29, 2008

Using Richt Text TextArea results in error (java.lang.Double cannot be cast to java.lang.String)

Well you guessed correctly from the title. There is something odd going on.
If we are passing on variables that are typed as numeric to an argument (height and width) that would conceivable accept numeric values we will get this error:

java.lang.Double cannot be cast to java.lang.String

Here is sample code to reproduce this:

<cfset iHeight=Val(200)>
<cfset iWidth=Val(500)>

<cfform name="myForm" method="POST" action="Self.cfm">

<cftextarea richtext="true"
toolbar="Basic"
name="MyRTField"
height="#iHeight#"
width="#iWidth#" value="">
</cftextarea>

</cfform>


This could easily occur when passing values as returns from functions. I found two ways of avoiding this.
a) specifically declare variables as strings

<cfset iHeight="200">
<cfset iWidth="500">


b) introduce space when passing arguments so as to force an implicit conversion

...
height=" #iHeight# "
width=" #iWidth# "

No comments: