velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Tilsted <til...@daimi.au.dk>
Subject Re: Calling methods on an object from a Velocity Template
Date Tue, 08 Aug 2006 18:10:23 GMT
That's a classic error :}

The CLASS also need to be public, not just the methods.

Citat Fakir Nooruddin <fsnooruddin@gmail.com>:

> Hello,
>
> I have been stumped by this for several hours. I have looked at
> available documentation & archives of this list, but to no avail.
> Hoping that someone on this list can set me straight.
>
> All that I am trying to do is call a public non-static method of an
> object that I pass into my template. The output of the template is:
>
>  Test is: TestItem@a7dd39
>
> Test is: $entry.getInfo()
>
> This tells me that the template knows that the object is of type
> TestItem, but it still refuses to give me the results of the getInfo()
> call. Instead, I get an "undefined reference" warning for the
> getInfo() call. Further, if I over-ride the toString method in the
> TestInfo class, the template correctly displays the results.
>
> The TestItem class is:
>
> class TestItem {
>
>     private String Info;
>
>     public TestItem()
>     {
> 	Info = "value of Info";
>     }
>
>     public String getInfo()
>     {
> 	return Info;
>     }
>
>     public void setInfo( String str )
>     {
> 	Info = str;
>     }
> }
>
> And the template is:
>
> <html>
>
> <h2> Test is: $entry </h2> <br>
> <h2> Test is: $entry.getInfo() </h2> <br>
>
> </html>
>
> My Java code populates the context like this:
>
> ctx.put("theList", personList );
>
> TestItem ti = new TestItem();
>
> ctx.put("entry", ti);
>
>
> Thanks in advance for your help!
>
> -Nooruddin
>
> p.s. I am using Velocity 1.4 with Tomcat 5.5 on Windows XP.
>
> ---------------------------------------------------------------------
> 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


Mime
View raw message