title: Converting the result of an FXML dialog
body: <p>I created a simple dialog with radio buttons</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;?import java.net.*?&gt;
  &lt;?import javafx.geometry.*?&gt;
  &lt;?import javafx.scene.control.*?&gt;
  &lt;?import javafx.scene.layout.*?&gt;
  &lt;?import javafx.scene.text.*?&gt;
  &lt;?import javafx.scene.image.*?&gt;
  &lt;?import javafx.scene.image.Image?&gt;
  
  
  &lt;Dialog fx:id="dialog"
      fx:controller="myapp.AddDialogController"
      xmlns:fx="http://javafx.com/fxml"&gt;
      &lt;dialogPane&gt;
          &lt;DialogPane prefWidth="400.0" prefHeight="300.0"&gt;
              &lt;stylesheets&gt;
                  &lt;URL value="@/css/styles.css" /&gt;
              &lt;/stylesheets&gt;
              &lt;content&gt;
                  &lt;VBox&gt;
                      &lt;fx:define&gt;
                          &lt;ToggleGroup fx:id="myToggleGroup"/&gt;
                      &lt;/fx:define&gt;
                      &lt;children&gt;
                          &lt;RadioButton text="Comment" toggleGroup="$myToggleGroup"/&gt;
                          &lt;RadioButton text="Survey" toggleGroup="$myToggleGroup"/&gt;
                          &lt;RadioButton text="Suggestion" toggleGroup="$myToggleGroup"/&gt;
                      &lt;/children&gt;
                  &lt;/VBox&gt;
              &lt;/content&gt;
          &lt;/DialogPane&gt;
      &lt;/dialogPane&gt;
  &lt;/Dialog&gt;
  </code></pre>
  
  <p>And I create it like this:</p>
  
  <pre><code>private String convertDialogResult(ButtonType buttonType) {
      if (buttonType == ButtonType.OK) {
          return "A";
      } else {
          return null;
      }
  }
  
  private Dialog&lt;String&gt; createAddDialog() throws ApplicationException {
  
      try {
          Dialog&lt;NodeViewModel&gt; dialog = FXMLLoader.load(getClass().getResource("/fxml/add_dialog.fxml"));
  
          dialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
          dialog.setResultConverter(this::convertDialogResult);
  
          return dialog;
      } catch (IOException e) {
          throw new ApplicationException(e);
      }
  }
  </code></pre>
  
  <p>But now I'd like not to return "A" all the time, but "A" if "Comment" is selected, "B" if "Survey" is selected, etc.</p>
  
  <p>How can I do it?</p>