Find file
Fetching contributors…
Cannot retrieve contributors at this time
122 lines (88 sloc) 3.01 KB


ActFramework can plugin different templating solutions. At the moment Rythm is fully supported. Freemarker and Velocity is limited supported.

Note to use freemarker and velcoity templating you need to add the dependencies into your pom.xml file respectively:

Freemarker templating dependency:


Velocity templating dependency:


template file location

The convention of locating a template file is:


For example, if you have a controller class defined as:

package com.mycom.myprj;

public class MyController {

    public void home() {

    public Foo getFoo() {
        return Foo.instance();

You can create two template files corresponding to the home() and getFoo() action methods:

  1. /src/main/resources/rythm/com/mycom/myprj/MyController/home.html
  2. /src/main/resources/rythm/com/mycom/myprj/MyController/getFoo.html

When the request to /foo endpoints accept application/json content, then you can create a json template at


Passing parameter to template

ActFramework use ASM to enhance your controller method so that you don't need to manually put template arguments into a Map type context, like what you did in Spring MVC:

public String foo(String a, String b, int c, ModelMap modelMap) {
    modelMap.put("a", a);
    modelMap.put("b", b);
    modelMap.put("c", c);
    modelMap.put("abc", a + b + c);
    return "/path/to/the/template";

In Act, your code could much more clean:

public Result foo(String a, String b, int c) {
    String abc = a + b + c;
    return render(a, b, c, abc);

And in your rythm template you declare your template argument and use them as follows:

@args String a, String b, int c
a = @a
b = @b
c = @c

Passing return result to template

If your action method just need to pass one parameter into the template, you can choose to return it:

public Foo getFoo() {
    return dao.findOne();

In your template you use name result to refer to the return instance:

@args Foo result
Foo is @result


Back to index