Reputation: 3244
I've decided to use custom template engine with Spring MVC framework.
my templates implemented in java and have method for rendering into String:
public String render(Map context);
how to configure spring to make them available in Controller beans as views, for example like:
ModelAndView modelAndView = new ModelAndView("activationPage"); // - view name which will actually be java class name reference.
modelAndView.addObject("validationResult", validationResult);
return modelAndView;
Model will be passed as context in code connecting spring and my template engine.
Upvotes: 3
Views: 1552
Reputation: 14373
Hi I am the author of Rythm template engine, about half year ago I am having the same requirement like you. What I did is to read the source code of Velocity and Freemarker view of SpringFramework. And then create the Rythm view for spring following their approach.
It's easy to follow something that is already there, and it makes your implementation in good quality to follow the official module. Good luck on you :-)
Upvotes: 2
Reputation: 403531
You need to implement org.springframework.web.servlet.View
(which should be easy, you already have something very similar to the render
method it needs), as well as org.springframework.web.servlet.ViewResolver
, which maps the view names (e.g. "activationPage") on your custom views.
Once you have that, drop a bean of your ViewResolver
class into the context, and (unless you've done something else that gets in the way) it should automatically be picked up by Spring and should just work. if you have other ViewResolvers already in there, they may get into a fight over who gets to resolve the view, in which case ask a new question.
Upvotes: 3