Fork me on GitHub

Rendering objects in HTML views

Of course you want to make your pages dynamic.

It is simple to do so. The Freemarker engine takes any Map and you can access its members inside the view.

public Result userDashboard(
        @PathParam("email") String email,
        @PathParam("id") Integer id,
        Context context) {

    Result result = Results.html();

    result.render("id", Integer.toString(id));
    result.render("email", email);

    return result;

}

The corresponding view looks like:

<html>
    <head>
        <title>Dashboard for user</title>
    </head>
    <body>

        <h1>hi ${email}</h1>

        <p>Your id seems to be: ${id}</p>
    </body>
</html>

Using simple ${email} tags you can access the content of the variables.