velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Geir Magnusson Jr." <ge...@optonline.net>
Subject Re: ReferenceException
Date Mon, 02 Jul 2001 22:45:10 GMT
piero de salvia wrote:
> 
> Hi guys,
> 
> It's one of those days when nothing works...

Monday...

> I have:
> 
> public class Hyperlink {
> 
>         public String   Location;
>         public String   Label;
> }
> 
> and in my servlet I do:
> 
> Hyperlink hl = new Hyperlink();
> hl.Label = "/site/section";
> hl.Location = "Section";
> ctx.put("hl", hl);
> 
> and in my template I do:
> 
> <a href="$hl.Location">$hl.Label</a>
> 
> and my result is:
> 
> <a href="$hl.Location">$hl.Label</a>
> 
> plus 2 ReferenceExceptions:
> 
> Tue Jul 03 00:29:21 GMT+02:00 2001   [warn]
> org.apache.velocity.runtime.exception.ReferenceException:
> reference : template = /piergi/layout/navbar.vm [line
> 6,column 42] : $hl.Location is not a valid reference.
> Tue Jul 03 00:29:21 GMT+02:00 2001   [warn]
> org.apache.velocity.runtime.exception.ReferenceException:
> reference : template = /piergi/layout/navbar.vm [line
> 6,column 56] : $hl.Label is not a valid reference.
> 
> Should I give up programming?

You could.  It wouldn't solve the problem though.

The problem is that Velocity will not let you get to members, just
methods.  So either make a set of getter/setter methods

public String getLocation()

etc

and all will work, or use the FieldMethodizer class to do fake it for
you.

geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
You have a genius for suggesting things I've come a cropper with!

Mime
View raw message