title: Play Framework - Register a custom DataBinder for dynamic fields
body: <p>Using Play 2.3.7 (Java) I have the following scenario.</p>
  
  <p>I have a class <code>CSVData</code> which contains a list of type <code>CSVField</code>. Here are the attributes for these classes:</p>
  
  <pre><code>public class CSVData{
  
  private String name;
  private String description;
  private String dataFilePath;
  private List&lt;CSVField&gt; fields;
  private Double latitude;
  private Double longitude;
  
  
  // rest of class... }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>public class CSVField {
      private String name;
      private String type;
  
  ...}
  </code></pre>
  
  <p>The difficulty when making a form to input <code>CSVData</code> is that I have this nested <code>List&lt;CSVField&gt;</code> attribute and <code>CSVField</code> is a custom type containing two strings. I need the form to be dynamic in that it should be able to accept an arbitrary amount of <code>CSVField</code>s (at least 1). According to the <a href="https://www.playframework.com/documentation/2.3.x/JavaForms" rel="nofollow noreferrer">Java Form Documentation</a>, it seems like I should register a custom DataBinder for CSVField, however I can't find any examples that do this with multiple input strings. <a href="https://stackoverflow.com/questions/8729444/how-to-bind-complex-types-in-play-framework-2-0">This example</a> is similar, but it only binds one field. </p>
  
  <p><a href="https://www.youtube.com/watch?v=3u0cJURbuCU" rel="nofollow noreferrer">Here is a video</a> of what type of user input I would like to have. I made my view using <a href="http://jsfiddle.net/aaki/hMJEy/1/" rel="nofollow noreferrer">this example code for adding dynamic fields</a>. The combination of the text field (name) and select dropdown item (type) is what I need to bind to a <code>CSVField</code> and then add to the <code>List&lt;CSVField&gt; fields</code> in the <code>CSVData</code> object. <strong>How can I do this using the Play Framework?</strong> </p>
  
  <hr>
  
  <p><strong>EDIT</strong>: In my controller I have tried this</p>
  
  <pre><code>Form&lt;CSVData&gt; formData = Form.form(CSVData.class).bindFromRequest();
  </code></pre>
  
  <p>And in the view I try this</p>
  
  <pre><code>@helper.repeat(csvForm("fields"), min = 1) { csvField =&gt;
  
      @multiDataField(csvField,
          label = "Column Name and Type",
          gsnTypes,
          help = "Enter the column names and respective types for the data items in the file")
  
  }
  </code></pre>
  
  <p>Where <code>multiDataField</code> is <a href="http://pastebin.com/SN4gWE3s" rel="nofollow noreferrer">this</a> template. But it doesn't bind the dynamic fields properly and throws an invalid validation error on <code>fields</code>. I think my problem is I don't know what <code>name</code> attributes to use in my <code>multiDataField</code> template. Any advice?</p>