Reference Class Properties
This Example shows you how to use class properties in your velocity template.Steps used in the code given below :
1: Initialize velocity run time engine through method init().
2: Create object of VelocityContext Class.
3: Use put() method of Class VelocityContext through object 'ctx'.
4: Define variable 'date' to hold the value of java.util.Date Class.
5: With the use of this date variable, we will access the values of day, month and year in .vm file.
CallClassMethods.java
package velocity.ClassReference; |
ClassMethods.vm
Day: $date.Date
|
Output :
Day: 23 |