You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Christoph Reck <Ch...@dlr.de> on 2001/01/25 13:48:28 UTC
Re: Class cast exception
Please send questions explicetely dealing to the Velocity
features to that list.
The simple answer is that Vel does not support accessing
the fields of an object (instance). When trying to get
data via the Bean-Like interface you need to keep the
initial capital to the Method. So your second snippet
should have looke like:
#foreach ($cd in $CDs)
<TR>
<TD>$cd.Artist</TD>
<TD>$cd.Title</TD>
<TD>$myLink</TD>
</TR>
#end
I have proposed to the Vel team to do automatic uppercasing
of the first letter when searching for the appropiate get
method - to be more bean-conform, but had no luck.
The reason for a class cast exception needs to be further
traced.
:) Christoph
Shaun Campbell wrote:
>
> Got a strange problem with Velocity I don't know if anyone can help with.
>
> If for example in a Velocity screen I have:
>
> #foreach ($cd in $CDs)
> <TR>
> <TD>$cd.getArtist()</TD>
> <TD>$cd.getTitle()</TD>
> <TD>$myLink</TD>
> </TR>
> #end
>
> everything work OK.
>
> If I access a variable out of the object instead of accessing it via an
> accessor get method I get a class cast exception eg
>
> #foreach ($cd in $CDs)
> <TR>
> <TD>$cd.artist</TD>
> <TD>$cd.title</TD>
> <TD>$myLink</TD>
> </TR>
> #end
>
> where artist and title are String member variables of the cd class.
>
> Any ideas what I am doing wrong?
>
> Thanks
>
> Shaun