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

FXMLLoader: event handler binding expects unnecessary controller property

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P5 P5
    • tbd
    • 7u21
    • javafx

      Consider this FXML:

      <SomeControl onFooChange="#fooChange"/>

      and this property in SomeControl:

        public ObjectProperty<EventHandler<ActionEvent>> onFooChangeProperty() {...}
        public EventHandler<ActionEvent> getOnFooChange() {...}
        public void setOnFooChange(EventHandler<ActionEvent> v) {...}

      Expected: FXMLLoader binds SomeControl.onFooChangeProperty to the controller method fooChange().
      Actual: LoadException is thrown: "SomeControl does not define a property model for "foo"."
      Workaround: rename SomeControl.onFooChangeProperty to SomeControl.onFooChangingProperty or anything which does not match onXXXChange.

      Apparently a special case in FXMLLoader.Element.addEventHandler assume that for any onXXXChange property there is an XXX property on the object. Instead of throwing the exception it should simply bind to the specified controller method. This should also not be a backwards compatibility problem because we simply replace the exception with more appropriate (in my opinion) processing.

      There is a potential conflict if SomeControl has both a foo property and an onFooChange property. Which one to bind to now? However, this should be a rare case because it does not make much sense. Currently the code would prefer binding to a change listener of the foo property.

            Unassigned Unassigned
            wlehmann Werner Lehmann
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Imported: