24

When I have added this following code to my project

Form<User> filledForm2 = userSignupForm.bindFromRequest();

It has stopped working by showing an error message which states:

Execution exception
[IllegalStateException: JSR-303 validated property 'Password' does not have a corresponding accessor for data binding - check your DataBinder's configuration (bean property versus direct field access)]

My User class was like that:

class User{
String username;
String Password;
}

Now how can to check/modify DataBinder's configuration in java play framework?

sadaf2605
  • 7,332
  • 8
  • 60
  • 103

5 Answers5

50

Actually this shouldn't be happening, as Play automatically generates getters and setters, see Guillaume's comment.

Therefore it's possible that your IDE is causing issues e.g. Guillaume's comment re Eclipse. Or that your sbt cache is corrupt and needs cleaning, which you can do with play clean-all (read about it here)

By the way, changing your Password attribute to password may have caused the cache to be re-generated and therefore fixed the issue.

Update:

For more recent versions of Play that use activator, it seems the following are the the up-to-date equivalents:

activator clean and activator clean-files

Darren Shewry
  • 10,179
  • 4
  • 50
  • 46
  • 3
    This is what's happening -- found it to also be a problem under 2.1.3. Just ran play clean and corrected the problem. – kpw Aug 16 '13 at 02:36
  • Same problem in 2.2.1. – nize Jan 11 '14 at 15:40
  • `play clean-all` was the solution, thanks. (play-2.2.2) – nyuwec Apr 07 '14 at 17:39
  • Another issue which i spent hours figuring out is that the fields that are being populated by the form need to be public. – toidiu Feb 07 '15 at 08:01
  • 1
    `activator clean` and `activator clean-files` works on play 2.4.6 – Jin Feb 27 '16 at 22:10
  • 1
    activator clean and activator clean-files works on play 2.5 as well – Sergey V. Jun 03 '18 at 02:13
  • 1
    I had the same issue with running play-2.6 (2.6.15, 2.6.17) from IDE (IntelliJ 2018.1 Community edition) as well. The solution is very similar. I've run from command line in the project folder the following commands: `sbt` , then `clean` and `run` – Sergey V. Jul 21 '18 at 14:46
2

My environment is Mac OS X 10.9.5 and run CentOS 7 with Vagrant. On CentOS the same problem happended, but on Mac OS didn't. Play Framework version is 2.3.8.

The commnad below didn't work in my case:

  activator clean
  activator clean-files

Though it's so weird, I had to define getter and setter to work Play Framework on CentOS7 successfully as following:

@Entity
public class Message extends Model{

    @Id
    public long id;

    @Constraints.Required
    public String name;


    //Add getter and setter to work successfully...
    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
Ataru
  • 544
  • 4
  • 7
0

I've fixed this issue by using activator clean && activator clean-files before doing activator dist

Casey Murray
  • 1,582
  • 17
  • 21
-1

I got the same error trying to validate int field in POJO using @Min(value = 0).

Solved by putting the annotation on getter in combination with @Valid in my bean.

Peter
  • 10,492
  • 21
  • 82
  • 132
iboz
  • 1
  • 2
-5

Had the same issue...

To remove this error, you should define your variables as public.

class User{
   public String username;
   public String password;
}
Mike
  • 391
  • 2
  • 16