velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matthew Van Horn <matthew_van_h...@yahoo.com>
Subject best practice question
Date Wed, 02 Mar 2005 13:58:35 GMT
I use a Constants class in my application to hold a bunch of strings 
used for things like request attribute keys etc. In my templates, I 
would also like to eliminate the hard-coded strings, and I thought I 
could do that by using the Constants class as a tool.

<tool>
	<key>const</key>
	<scope>application</scope>
	<class>com.foo.util.Constants</class>
</tool>

public class Constants {

	public static final String PROPERTY = "my.property";
	//etc..
	
	//I even tried this:
	public static String getPROPERTY() {
		return PROPERTY;
	}
}

in my template
$const.PROPERTY
$const.getPROPERTY()
both turn up as invalid references.

but $const.toString() works, so an object must be there.

Is this something to do with static methods? I added a non-static method 
to test, but that didn't work either.

Do I need to implement the ViewTool interface? What should I do in 
init() then?

According to the docs available I thought this was possible, but now I 
am stumped. Hope I won't feel too stupid upon figuring this out.

Thanks for any help,
Matt Van Horn

---------------------------------------------------------------------
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