Playframework JSR-303 validated “field” does not have a corresponding accessor for data binding

后端 未结 5 1240
庸人自扰
庸人自扰 2020-12-14 01:32

When I have added this following code to my project

Form filledForm2 = userSignupForm.bindFromRequest();

It has stopped workin

相关标签:
5条回答
  • 2020-12-14 02:15

    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.

    0 讨论(0)
  • 2020-12-14 02:21

    Had the same issue...

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

    class User{
       public String username;
       public String password;
    }
    
    0 讨论(0)
  • 2020-12-14 02:25

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

    0 讨论(0)
  • 2020-12-14 02:28

    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;
        }
    }
    
    0 讨论(0)
  • 2020-12-14 02:30

    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

    0 讨论(0)
提交回复
热议问题