title: JavaFX custom cell factory with custom Objects
body: <p>I am trying to have a custom <code>ListView</code> made of custom <code>Cell</code> based on a list of custom <code>objects</code>.</p>
  
  <p>The custom object is class name called <code>Message</code> which contains a few fields for the message <strong>content</strong>, <strong>recipient</strong>, <strong>timestamp</strong> and <strong>status</strong> (read, sent etc.).</p>
  
  <p>After looking at this question : <a href="https://stackoverflow.com/questions/19588029/customize-listview-in-javafx-with-fxml">Customize ListView in JavaFX with FXML</a> I have successfully : </p>
  
  <ol>
  <li>created a ListView with <strong>custom cells</strong> where the cell design is defined in a <strong>FXML file</strong> ;</li>
  <li>associated a <strong>controller</strong> so that each cell data can be filled with the current item of the collection ;</li>
  </ol>
  
  <p>However, I failed to link both : I cannot seem to find a way so that the current item of the ListView is sent the <strong>Cell Controller</strong>.</p>
  
  <p>Here is my code for the cell factory and the ListView filling of items:</p>
  
  <pre><code>final ObservableList observableList = FXCollections.observableArrayList();
  observableList.setAll(myMessages); //assume myMessage is a ArrayList&lt;Message&gt;
  conversation.setItems(observableList); //the listview
  conversation.setCellFactory(new Callback&lt;ListView&lt;Message&gt;, ListCell&lt;Message&gt;&gt;() {
      @Override
      public ConversationCell&lt;Message&gt; call(ListView&lt;Message&gt; listView) {
          return new ConversationCell();
      }
  });
  </code></pre>
  
  <p>And now, the ConversationCell class :</p>
  
  <pre><code>public final class ConversationCell&lt;Message&gt; extends ListCell&lt;Message&gt; { 
  
      @Override
      protected void updateItem(Message item, boolean empty) {
          super.updateItem(item, empty);
          ConversationCellController ccc = new ConversationCellController(null);
          setGraphic(ccc.getView());
      }
  }
  </code></pre>
  
  <p>I cannot show the ConversationCellController but all I can say, this is where (in its constructor) I load the FXML file that designs the cell and then I can fill the values with the given Message item. </p>
  
  <p>The <code>getView()</code> method returns the <strong>root pane</strong> that contains the now-filled-and-designed cell.</p>
  
  <p>As I previously say, the designing work, but I cannot seem to link the ListView items with the <strong>CellFactory</strong> because in method </p>
  
  <blockquote>
    <p>protected void updateItem(Message item, boolean empty)</p>
  </blockquote>
  
  <p><strong>empty</strong> is set to <strong>true</strong> and item is indeed <strong>null</strong>.</p>
  
  <p>What can I do to make this work ?</p>