Could FXML use an interface and dynamic proxy for the passive view interface?

Greg Brown greg.x.brown at
Fri Dec 16 16:38:05 PST 2011

>> I'm having a hard time making up in my mind how you would envision your
>> passive dynamic view interface to work. Could you show us/me some pseudo
>> code?
> Well, the idea is that I might define:
> public interface MyView {
>    public StringProperty nameProperty();
>    public ObjectProperty<EventHandler<ActionEvent>> submitActionProperty();
> }
> And then in my Controller, I would just work with this interface. I wouldn't use @FXML or talk to the view directly. Instead, there would be a way for the FXMLLoader to inject an implementation of this interface to my controller via the constructor (or whatnot). This part I haven't ironed out, because in theory you just want:
> public class MyController {
>    private MyView myView;
>    private Customer customer;
>    public MyController(MyView myView) {
>        // create or get the customer
>        // bind the customer to the nameField of the myView
>        myView.submitActionProperty().set(new EventHandler<ActionEvent>() { ... });
>    }
> }
> The FXML file would maybe have been designed by name convention to match the MyView so that the FXMLLoader knows how to associate the property defined in the MyView with a concrete property in the FXML file. This part I'm not sure of and would have to think more (I don't think you want to annotate the MyView because that sort of defeats the purpose of separation of concerns).

To me, this just seems a lot harder to understand and work with than simply mapping a named object in your markup to a field in your controller. From a pure MVC perspective, a controller is *supposed* to know about the view. Controllers are the glue that bind the view and the model together. So I'm not sure what you might achieve by adding this layer of indirection. But maybe I am missing something.


More information about the openjfx-dev mailing list