Skip to content


Subversion checkout URL

You can clone with
Download ZIP
template engine plugin for vraptor
Java Scala
Tree: 852363fafd

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.



A simple library to render templates with vraptor.

The idea is to make the default rendering engine independent of the chosen template (Freemarker, Velocity ...) Simply add your preferred implementation in the classpath.

Engines Supported

  • Velocity
  • Freemarker
  • Scalate (SSP Scaml, Jade, Mustache)


Put vraptor-template.jar and dependencies in your WEB-INF/lib folder. You can get a copy here Add packages on web.xml


Rendering using TemplateService

    public class DashboardController {

        private final Clients clients;
        private final TemplateService service;

        public DashboardController(Clients clients, TemplateService service) {
            this.clients = clients;
            this.service = service;

        public void dashboard(){
            service.use("clients/dashboard").with("clients", clients.listAll()).render();


Rendering using Result

    import static*;

    public class DashboardController {

        private final Clients clients;
        private final Result result;

        public DashboardController(Clients clients, Result result) {
            this.clients = clients;
            this.result = result;

        public void dashboard(){
            result.use(template()).with("clients", clients.listAll()).render();


Implicit objects

Objects injected by the library:

  • request
  • context path
  • localization
  • validator

Decorating templates

To inject other objects just build a class like this:

public class CustomDecorator implements TemplateDecorator {

    private final User user;

    public CustomDecorator(User user) {
        this.user = user;

    public void decorate(Template template){
        template.with("user", user);


At the end of method execution, VRaptor will dispatch the request to the template at /WEB-INF/templates/clients/dashboard.(vm, ftl, ssp...). The convention for the default view is /WEB-INF/templates//..


To make the templates more "DRY", the binds and imports of attributes passed to the template are resolved automatically by the library. So it's not necessary to declare any attribute in the header of your template, like this:

<%@ val model: Person %>
<% import model._ %>
<p>Hello ${name}, what is the weather like in ${city}</p>

Just go directly to the methods:

<p>Hello ${person.getName}, what is the weather like in ${person.getCity}</p>

To pass collections:

result.use(template()).with("clients", clients.listAll(), Client.class).render()

So to iterate just do:

#for(client <- clients)
Something went wrong with that request. Please try again.