You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Matthew Van Horn <ma...@ashleyassociates.co.jp> on 2004/08/03 12:09:48 UTC
Class cast issue?
I have a typesafe enum class with methods:
public final Serializable getEnumCode() {
return enumCode;
}
public String toString() {
return name;
}
I put a number of these objects into a SortedSet, and in my template I
try:
#foreach($obj in $objSet)
<option value="$obj.enumCode">$obj</option>
#end
This outputs:
<option value="$obj.enumCode">Foo</option>
<option value="$obj.enumCode">Bar</option>
<option value="$obj.enumCode">Baz</option>
I have tried :
<option value="$obj.getEnumCode()">
And
<option value="$obj.getEnumCode().toString()">
But none of them seem to return a value.
Does it have anything to do with the fact that the method returns
Serializable? How can I get it to do the obvious?
Thanks,
Matt
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: Class cast issue?
Posted by Kishore Senji <ks...@gmail.com>.
Please make sure that the method enumCode exists in the Object that
$obj refers to.
On Tue, 3 Aug 2004 19:09:48 +0900, Matthew Van Horn
<ma...@ashleyassociates.co.jp> wrote:
> I have a typesafe enum class with methods:
>
> public final Serializable getEnumCode() {
> return enumCode;
> }
>
> public String toString() {
> return name;
> }
>
> I put a number of these objects into a SortedSet, and in my template I
> try:
>
> #foreach($obj in $objSet)
> <option value="$obj.enumCode">$obj</option>
> #end
>
> This outputs:
>
> <option value="$obj.enumCode">Foo</option>
> <option value="$obj.enumCode">Bar</option>
> <option value="$obj.enumCode">Baz</option>
>
> I have tried :
> <option value="$obj.getEnumCode()">
> And
> <option value="$obj.getEnumCode().toString()">
>
> But none of them seem to return a value.
>
> Does it have anything to do with the fact that the method returns
> Serializable? How can I get it to do the obvious?
>
> Thanks,
> Matt
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
RE: Class cast issue?
Posted by Matthew Van Horn <ma...@ashleyassociates.co.jp>.
I declared the superclass public and that solved the problem. Thanks for
the help!
> > On Wed, 2004-08-04 at 00:02, Nathan Bubna wrote:
> >
> > > is the enum class declared public? Velocity cares a lot about
> > > things being public methods in public classes.
> >
> > It is a public class that extends from a class which is package (as
> > below). I am going to change this, as I think it is the
> cause, and I
> > don't need the parent class not to be public.
> >
> > Unfortunately I can't test at the moment.
> >
> > Just curious - is this how it is supposed to work? (All
> ancestors must
> > also be public)
>
> If the method is overridden in the subclass, then it's
> sufficient if just the subclass is public, otherwise, the
> superclass also needs to be public.
> >
> > abstract class Foo {
> > public final Serializable getEnumCode() {
> > return enumCode;
> > }
> > public String toString() {
> > return name;
> > }
> > }
> >
> > public class Bar extends Foo {}
> >
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: Class cast issue?
Posted by Kishore Senji <ks...@gmail.com>.
On Wed, 04 Aug 2004 08:49:01 +0900, Matthew Van Horn
<ma...@yahoo.com> wrote:
>
>
> On Wed, 2004-08-04 at 00:02, Nathan Bubna wrote:
>
> > is the enum class declared public? Velocity cares a lot about things being
> > public methods in public classes.
>
> It is a public class that extends from a class which is package (as
> below). I am going to change this, as I think it is the cause, and I
> don't need the parent class not to be public.
>
> Unfortunately I can't test at the moment.
>
> Just curious - is this how it is supposed to work? (All ancestors must
> also be public)
If the method is overridden in the subclass, then it's sufficient if
just the subclass is public, otherwise, the superclass also needs to
be public.
>
> abstract class Foo {
> public final Serializable getEnumCode() {
> return enumCode;
> }
> public String toString() {
> return name;
> }
> }
>
> public class Bar extends Foo {}
>
> >
> > Nathan Bubna
> > nathan@esha.com
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> --
> Matthew Van Horn <ma...@yahoo.com>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: Class cast issue?
Posted by Matthew Van Horn <ma...@yahoo.com>.
On Wed, 2004-08-04 at 00:02, Nathan Bubna wrote:
> is the enum class declared public? Velocity cares a lot about things being
> public methods in public classes.
It is a public class that extends from a class which is package (as
below). I am going to change this, as I think it is the cause, and I
don't need the parent class not to be public.
Unfortunately I can't test at the moment.
Just curious - is this how it is supposed to work? (All ancestors must
also be public)
abstract class Foo {
public final Serializable getEnumCode() {
return enumCode;
}
public String toString() {
return name;
}
}
public class Bar extends Foo {}
>
> Nathan Bubna
> nathan@esha.com
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
--
Matthew Van Horn <ma...@yahoo.com>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: Class cast issue?
Posted by Nathan Bubna <na...@esha.com>.
Matthew Van Horn said:
> I have a typesafe enum class with methods:
>
> public final Serializable getEnumCode() {
> return enumCode;
> }
>
> public String toString() {
> return name;
> }
>
> I put a number of these objects into a SortedSet, and in my template I
> try:
>
> #foreach($obj in $objSet)
> <option value="$obj.enumCode">$obj</option>
> #end
>
> This outputs:
>
> <option value="$obj.enumCode">Foo</option>
> <option value="$obj.enumCode">Bar</option>
> <option value="$obj.enumCode">Baz</option>
>
> I have tried :
> <option value="$obj.getEnumCode()">
> And
> <option value="$obj.getEnumCode().toString()">
>
> But none of them seem to return a value.
>
> Does it have anything to do with the fact that the method returns
> Serializable?
highly unlikely. Velocity doesn't much care what the return type is.
> How can I get it to do the obvious?
is the enum class declared public? Velocity cares a lot about things being
public methods in public classes.
Nathan Bubna
nathan@esha.com
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org