velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Fakir Nooruddin" <>
Subject Calling methods on an object from a Velocity Template
Date Tue, 08 Aug 2006 18:06:43 GMT

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:


<h2> Test is: $entry </h2> <br>
<h2> Test is: $entry.getInfo() </h2> <br>


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!


p.s. I am using Velocity 1.4 with Tomcat 5.5 on Windows XP.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message