Issue with bindFromRequest in Play! Framework 2.3

前端 未结 6 1604
夕颜
夕颜 2021-01-12 01:37

I\'m trying to use the automatic binding feature of Play, without success. I\'m developing in Java, on Eclipse 4.4 Luna.

Here is my form :

6条回答
  •  既然无缘
    2021-01-12 02:03

    In your code you have :

    Users u = Form.form(Users.class).bindFromRequest().get(); 
    

    Try with this instead :

    Users user = new Users();
    Form  u = Form.form(Users.class).fill(user).bindFromRequest();
    

    EDIT :

    May be the problem is the input types you're using. Try to generate your form like this :

    @form(routes.Backend.createUser()) {
    
                 @inputText(userForm("first_name")) 
    @inputText(userForm("first_name"))
    @inputText(userForm("email"))
    @inputText(userForm("pin"))
    @inputText(userForm("status"))
    @checkbox(userForm("is_guest"))
    }

    Then in User Entity : try to change all columns type to String

    @Entity
    public class Users extends Model {
    
    // Database columns
    @Id
    public int user_id;
    
    public String first_name;
    public String last_name;
    public String email;
    public String pin;
    public String status;
    public String is_guest;
    
    }
    

    In your controller :

    public class Backend extends Controller {
    
      public static Result createUser() {
        Form  userForm = Form.form(Users.class).bindFromRequest();
        Users user = userForm .get();
        user.save();
    }
    }  
    

提交回复
热议问题