Ashesh Ashesh - 4 months ago 13x
HTML Question

Java Play: bindFromRequest() not working

I'm experimenting with Java Play and I've hit an immediate roadblock. The situation is quite straightforward and the setup, simple.

I have a model class called

that is very simple and looks like this;

package models.models;

import play.db.ebean.Model;

import javax.persistence.Entity;
import javax.persistence.Id;

* Created by asheshambasta on 25/07/14.
public class Person extends Model {

public Integer id;

public String name;

And I have a route defined as;

POST /person controllers.Application.addPerson()

Next, I have an action
, which is

public static Result addPerson() {
Person person = form(Person.class).bindFromRequest().get();;
return redirect(controllers.routes.Application.index());

And the index.scala.html looks like:

@(message: String)

@main("Welcome to Play") {
<form action="@routes.Application.addPerson()" method="post">
<input type="text" name="name" />
<button>Add person</button>

I've also checked my browser debug tools and I see the
form element correctly being posted to the server.

What happens is weird: none of the form parameters seem to be visible in the action. As you can see, I have two
's, each of which show me a null for the
property in the
object, as well as when attempted to be retrieved using

I've tried what I could see is the best way to go about this problem but I've not really seen much about this issue online. And this seems too basic to be an issue with the Play framework.

What am I doing wrong here?

As a note, I'm on a Mac, and I'm using mySQL to store data.


While trying play with Java, I was stuck with the same problem too.

Cause : The problem seems to arise when you have Eclipse project preference set to Build automatically. This messes up the classes generated by play and overrides it with the classes generated by eclipse upon a change.

The solution : Disable the 'build automatically' from Project settings and from the terminal, do a play clean to create classes from Play!

Let me know if this works, a lot of people face the same problem. This should probably be a hint in the documentation itself Reference.