Hello there,
I’d like to know if there is a possibility to dynamically change a velocity template. I understood to get some server side object into vm file was to go with the context:
SourceObject sourceObject = ao.get(SourceObject.class,1);
Map<String, Object> context = new HashMap<String, Object>();
context.put(“source-object”,sourceObject);
res.setContentType(“text/html;charset=utf-8”);
templateRenderer.render(“templates/object-mapping.vm”, context, res.getWriter());
and access it like this in the vm file:
#foreach($field in $source-object.getSourceFields())
$field.getName()
#end
Which works pretty fine. Now I wanted to change the sourceObject ID (to get another object) through some javascript and render the changes again. So call the server side, pass the object id and render the template with the “new” context:
SourceObject sourceObject = ao.get(SourceObject.class,2);
Map<String, Object> context = new HashMap<String, Object>();
context.put(“source-object”,sourceObject);
res.setContentType(“text/html;charset=utf-8”);
templateRenderer.render(“templates/object-mapping.vm”, context, res.getWriter());
But it doesn’t seem to work. Are there any right “JIRA ways” how to change the velocity template dynamically?