PDA

View Full Version : LinkTool when using VelocityEngineUtils.mergeTemplateIntoString


jprogramista
Jun 18th, 2007, 06:22 AM
Hello,
I have trouble with LinkTool from VelocityTools when using VelocityEngineUtils.mergeTemplateIntoString common way to produce email bodies from Velocity templates - it seems that LinkTool heavily depends on request/response parameters which are not provided when you just assign LinkTool to the model (the same example for DateTool mentioned on this forum work but not for LinkTool).
I have simple code:

Map<String,Object> model = new HashMap<String,Object>();
LinkTool linkTool = new LinkTool();
model.put("linkTool", linkTool);
DateTool dateTool = new DateTool();
model.put("theDate", dateTool);
String text = VelocityEngineUtils.mergeTemplateIntoString(
velocityEngine, "com/test/templates/vm/registration-confirmation.vm", model);

So in template I always get NullPointerException when get data from eg. $linkTool.absolute("http://localhost:8080/testapp/index.jsp"). As I saw sources I need to provide ViewContext object to the init() method of the tool. My question is: Is there in Spring available such object, or can be created any? Maybe there is any other solution to use LinkTool in such environment (without HttpServletRequest/HttpServletResponse in ViewContext)?

Best Regards,
Adr

mpetrashev
Jun 18th, 2007, 06:52 AM
Did you try initiate org.springframework.web.servlet.view.velocity.Velo cityConfigurer
instance before merging?