title: Play Framework - How to fix troubleshootings about NULL values with bindFromRequest() and get() methods
body: <p>I programming a little website with Java Play Framework 2.6.21 with sbt version 1.2.8, Scala version 2.11.12. I try to create some forms with Form&lt;> class, but I have some problems with bindFromRequest() and get() methods that always return NULL. How can I fix it?</p>
  
  <p>I tried some answers about this problem (including Stack Overflow), but nothing worked.</p>
  
  <p>I tried to change SBT's version, same result.</p>
  
  <p>I tried to include Ebean, but it is worse, I have more errors about injecting...</p>
  
  <p>Here is my class</p>
  
  <pre class="lang-java prettyprint-override"><code>package models;
  
  import play.data.validation.Constraints;
  import javax.persistence.*;
  import java.util.HashSet;
  import java.util.Set;
  
  @Entity
  @Table(name = "usernames")
  public class User {
      @Id
      @GeneratedValue
      public Integer Id;
  
      public String name;
  
      public User(){}
  
      public User(Integer Id, String name) {
          this.Id = Id;
          this.name = name;
      }
  
      private static Set&lt;User&gt; users;
  
      static {
          users = new HashSet&lt;&gt;();
  
          users.add(new User(1, "John"));
          users.add(new User(2, "Jack"));
  
      }
  
      public static Set&lt;User&gt; getAllUsers() {
          return users;
      }
  
      public static User userById(Integer Id) {
          for (User user : users) {
              if (Id.equals(user.Id)) {
                  return user;
              }
          }
  
          return null;
      }
  
      public static void addUser(User user) {
          users.add(user);
      }
  
      public static String validate() {
          return "Good";
      }
  
      public void setId() {
          this.Id = Id;
      }
  
      public void setName() {
          this.name = name;
      }
  
      public Integer getId() {
          return this.Id;
      }
  
      public String getName() {
          return this.name;
      }
  }
  </code></pre>
  
  <p>Here is my routes files for my website</p>
  
  <pre><code>#The user webpage
  GET /user controllers.UserController.index()
  GET /user/newUser   controllers.UserController.create()
  GET /user/resultCreate controllers.UserController.resultCreate()
  GET /user/:id   controllers.UserController.show(id : Integer)
  </code></pre>
  
  <p>Here is my HTML file</p>
  
  <pre class="lang-html prettyprint-override"><code>@(userForm : Form[models.User])
  @import helper._
  &lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
      &lt;head&gt;
          &lt;meta charset="UTF-8"&gt;
          &lt;title&gt;Create a new user&lt;/title&gt;
          &lt;link rel="stylesheet" href='@routes.Assets.at("stylesheets/helloworld.css")'&gt;
          &lt;link rel="icon" href='@routes.Assets.at("images/favicon.png")'&gt;
      &lt;/head&gt;
      &lt;body&gt;
      @helper.form(routes.UserController.resultCreate()) {
          @helper.CSRF.formField
          @helper.inputText(userForm("Id"))
          @helper.inputText(userForm("name"))
          &lt;button type="submit"&gt;Create widget&lt;/button&gt;
      }
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And finally here is the part of the code for the result</p>
  
  <pre class="lang-java prettyprint-override"><code>public Result resultCreate() {
          Form&lt;User&gt; userForm = formFactory.form(User.class).bindFromRequest(request());
          System.out.println(userForm);
          User user;
          if(!userForm.hasErrors()) {
              Logger.debug("Id : " + userForm.get().Id);
              user = userForm.get();
              Logger.debug(User.validate());
          } else {
              System.out.println("Not good");
              user = null;
          }
          return ok(views.html.resultCreate.render(user));
      }
  </code></pre>
  
  <p>I except that the entered user displays in the result webpage, but nothing is displayed. I tested to display in a console and the value of the class attributes is NULL.</p>
  
  <p>Here is what is displayed on my console :</p>
  
  <pre><code>Form(of=class models.User, data={name=Toto, csrfToken=109d71e13e39d0c23e8874b4c71f9e6387890cdc-1553372828827-d4c200687a8689d336c0c962, Id=7}, value=Optional[models.User@6b8e
  fb4f], errors=[ValidationError(,[Good],[])])
  </code></pre>
  
  <p>I don't have any suggestions.</p>