Fork me on GitHub

Form parsing

Advanced object parsing and rendering

Wouldn’t it be cool under some circumstances to parse and render objects directly - without even knowing about path parameters?

Easily possible.

1) Let’s suppose you got an object like that:

public class Contact {

    private String name;
    private String email;
    public String description;
    public int id;

    public Contact() {}

    public String getName() {
        return name;
    public void setName(String name) { = name;
    public String getEmail() {
        return email;
    public void setEmail(String email) { = email;


2) And suppose you got a post form like that:

<form action="/contactForm" method="post">
    <table class="form">
            <th><label for="name"> Name </label></th>
            <td><input class="input_full" type="text" id="name" name="name" />

            <th><label for="email"> Email </label></th>
            <td><input class="input_full" type="email" id="email"
                name="email" /></td>

            <th><label for="description"> Description </label></th>
            <td><input class="input_full" type="text" id="description"
                name="description" /></td>
            <th><label for="id"> ID number </label></th>
            <td><input class="input_full" type="number" id="id"
                name="id" /></td>

        <input type="submit" value="Send" /> <input type="reset"

3) You can then parse that request simply by specifying the object in the application controller:

public Result postContactForm(Context context, Contact contact) {

    return Results.html().render(contact);

Really simple. Ninja maps the post request form parameters directly to the object you specified. Primitive types (or their object wrapper types) will be automatically converted and mapped.

But wait - there is a bit more: You can even render the object directly via “Results.html().render(contact)”.

The corresponding Freemarker template would then look like:


“contact” is the lower camel case version of the object’s class name. And you can then access the fields (or getters / setters in case the fields are private) via “”.