Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8132450

Custom conversion in FXML

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8u45
    • javafx
    • None
    • generic
    • generic

      FXML can invoke some conversions on the fly when using binding expressions, e. g. text="${a.b}") will convert getB(s) value into a String if it is not already a String. In real world applications there often is a need to use custom conversions. For example, when a domain model provides instances of "Fruit" typically you don't want to have the toString conversion result on the screen (i. e. FRUIT) but actually you like to get the localized result (i. e. "Fruit" in English or "Frucht" in German).

      Unfortunately there is no way to specify this common need in pure FXML. Not even is there a Bindings.convert() variant that allows to specifiy either a custom StringConverter to support this common need.

      Hence I'd like to suggest that (a) there should be an additional Bindings.convert(ObservableValue, StringConverter customConverter) method, and (b) FXML should be able to invoke _explicitly_specified_ static Bindings methods (i.e. text="${convert(a.b, customConverter)}").

            Unassigned Unassigned
            mkarg Markus Karg
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: