title: JavaFX datepicker not updating value
body: <p>Bit of an odd one, I'm using JavaFX 8 and am having some odd behaviour I picked up during my Jubula testing.</p>
  
  <p>I have a datepicker control that is created with the following code:</p>
  
  <pre><code>public DatePicker getDatePicker(DtDate defaultDate, int width){
      DatePicker dtpckr = new DatePicker();
      dtpckr.setMaxWidth(width);
      dtpckr.setMinWidth(width);
      dtpckr.setConverter(new StringConverter&lt;LocalDate&gt;() {
          private DateTimeFormatter dateTimeFormatter=DateTimeFormatter.ofPattern("yyyy/MM/dd");
          @Override
          public String toString(LocalDate localDate) {
              if(localDate==null)
                  return "";
              return dateTimeFormatter.format(localDate);
          }
          @Override
          public LocalDate fromString(String dateString) {
              if(dateString==null || dateString.trim().isEmpty())
                  return null;
              return LocalDate.parse(dateString,dateTimeFormatter);
          }
      });
      dtpckr.setPromptText("yyyy/MM/dd");
      dtpckr.setValue(LocalDate.parse(defaultDate.toString(), DateTimeFormatter.ofPattern("yyyy/MM/dd")));
      return dtpckr;
  }
  </code></pre>
  
  <p>That works fine and the control is created on the form and works as expected. If I use the calendar to pick the date, the value is updated.</p>
  
  <p>Now, for the odd part, if I enter in the datepicker and manually type the date in (E.g. 2017/10/11) and then exit the control by either tabbing or clicking on the next textbox on the form, the datepicker localdate value doesn't get updated. The only method to update the date would be to press enter to force the datepicker to realise a new value is present. This causes another problem as I have the following code:</p>
  
  <pre><code>public void createSetDateAndTimeControls(){
      DtDateAndTime currentDateAndTime;
      try {
          currentDateAndTime = systemstateController.getServerDateTime();
          /*
           * Creating controls to be used on the form
           */
          int width = 150;
          DatePicker dtpckr = getDatePicker(currentDateAndTime.date, width);
          Label lblDate = new Label("Date:");
          Label lblTimeHour = new Label("Hour:");
          Label lblTimeMinute = new Label("Minute:");
          Label lblTimeSecond = new Label("Second:");
          TextField txtfldCurrentSetSecond = new TextField();
          TextField txtfldCurrentSetMinute = new TextField();
          TextField txtfldCurrentSetHour = new TextField();
          Slider sldrHourPicker = getSlider(width, SliderType.Hour, txtfldCurrentSetHour, currentDateAndTime.time);
          Slider sldrMinutePicker = getSlider(width, SliderType.Minute, txtfldCurrentSetMinute, currentDateAndTime.time);
          Slider sldrSecondPicker = getSlider(width, SliderType.Second, txtfldCurrentSetSecond, currentDateAndTime.time);
          /*
           * Adding a grid pane to keep controls in correct place and aligned correctly
           */
          GridPane grdpn = new GridPane();
          grdpn.add(lblDate, 1, 1);
          grdpn.add(dtpckr, 2, 1, 2,1);
          grdpn.add(lblTimeHour, 1, 2);
          grdpn.add(sldrHourPicker, 2, 2, 2 ,1);
          grdpn.add(txtfldCurrentSetHour, 4, 2);
          grdpn.add(lblTimeMinute, 1, 3);
          grdpn.add(sldrMinutePicker, 2, 3, 2, 1);
          grdpn.add(txtfldCurrentSetMinute, 4, 3);
          grdpn.add(lblTimeSecond, 1, 4);
          grdpn.add(sldrSecondPicker, 2, 4, 2, 1);
          grdpn.add(txtfldCurrentSetSecond, 4, 4);
          /*
           * Creating buttons for user to press
           */
          Button bttnOK = new Button("Change date and time");
          bttnOK.setOnAction(new EventHandler&lt;ActionEvent&gt;() {
              @Override
              public void handle(ActionEvent event) {
                  try {
                      if (checkIfAllDialogHasBeenFilledIn(grdpn)){
                          LocalDate test = dtpckr.getValue();
                          if (systemstateController.oeSetClock(ICrashUtils.setDateAndTime(dtpckr.getValue().getYear(), dtpckr.getValue().getMonthValue(), dtpckr.getValue().getDayOfMonth(),
                                  (int)Math.floor(sldrHourPicker.getValue()), (int)Math.floor(sldrMinutePicker.getValue()), (int)Math.floor(sldrSecondPicker.getValue()))).getValue())
                              showOKMessage("Updated", "Date and time was updated successfully");
                          else
                              showErrorMessage("Error", "There was an error updating the date and time");
                      }
                      else
                          showUserCancelledActionPopup();
                  } catch (ServerOfflineException | ServerNotBoundException e) {
                      showExceptionErrorMessage(e);
                  }
              }
          });
          bttnOK.setDefaultButton(true);
          grdpn.add(bttnOK, 2, 5, 3, 1);
          Button bttnSetNow = new Button("Now");
          bttnSetNow.setOnAction(new EventHandler&lt;ActionEvent&gt;() {
              @Override
              public void handle(ActionEvent event) {
                  dtpckr.setValue(LocalDate.now());
                  LocalTime time = LocalTime.now();
                  sldrHourPicker.setValue(time.getHour());
                  sldrMinutePicker.setValue(time.getMinute());
                  sldrSecondPicker.setValue(time.getSecond());
              }
          });
  
          grdpn.add(bttnSetNow, 4, 1);
          /*
           * End of creating controls to be used on the form
           */
          anchrpnActivator.getChildren().add(grdpn);
          AnchorPane.setTopAnchor(grdpn, 0.0);
          AnchorPane.setRightAnchor(grdpn, 0.0);
          AnchorPane.setLeftAnchor(grdpn, 0.0);
          AnchorPane.setBottomAnchor(grdpn, 0.0);
      } catch (ServerOfflineException | ServerNotBoundException e) {
          showExceptionErrorMessage(e);
      }
  }
  </code></pre>
  
  <p>Which has the following line:</p>
  
  <pre><code>bttnOK.setDefaultButton(true);
  </code></pre>
  
  <p>This means that if a user presses enter during the text entry on the date picker control, it fires off the <code>onaction</code> event, before the user has put in data in the other controls, and I don't particularly want that.</p>
  
  <p>So the question is, why doesn't the <code>dtpckr.getValue()</code> change if a user enters text into the box and then leaves the box without pressing enter? I can't find an event to call on user leaving the datepicker box or a property of the datepicker to get the text value of the control and compare it to the value of <code>dtpckr.getValue()</code>. Is there something that I'm missing here?</p>
  
  <p>Let me know if you need more information!</p>
  
  <h2><strong>[Edit]</strong></h2>
  
  <p><a href="https://bugs.openjdk.java.net/browse/JDK-8092295?page=com.atlassian.jira.plugin.system.issuetabpanels:changehistory-tabpanel" rel="noreferrer">It appears this might be a bug in the current datepicker setup in JavaFX</a></p>
  
  <p>I might have to remove the default button and put in an enter press in the Jubula test to make this work properly. Unless someone has an alternative?</p>