When I try to use velocity’s FieldMethodizer
variable in my template it prints error.
I’m using SparkJava framework and velocity template engine.
public static String render(Map<String, Object> model, String templatePath) {
model.put("WebPath", new FieldMethodizer("Path.Web"));
return strictVelocityEngine().render(new ModelAndView(model, templatePath));
}
private static VelocityTemplateEngine strictVelocityEngine() {
VelocityEngine configuredEngine = new VelocityEngine();
configuredEngine.setProperty("runtime.references.strict", true);
configuredEngine.setProperty("resource.loader", "class");
configuredEngine.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
return new VelocityTemplateEngine(configuredEngine);
}
I get error
Could not add Path.Web for field methodizing: Path.Web
2
Answers
I changed
model.put
line tomodel.put("WebPath", new FieldMethodizer(new Path.Web()));
to resolve this.You need to add to model the full class name as
com.package.Path
when using FieldMethodizerAnd then use in template
$WebPath.Web