[REVIEW] Make controller instantiation customizable

Greg Brown greg.x.brown at oracle.com
Wed Dec 14 05:52:07 PST 2011

> I think in a reasonably clean design you wouldn't want a reference to
> the controller or even instantiating the controller in the view. IMO the
> view should have no knowledge at all about the controller. 

That's sort of how it works in JavaFX 2.0 - the view does not have a reference to the controller. However, this makes certain things difficult - particularly establishing bindings between the controller and any view objects; e.g. <TextField text="${controller.model.firstName}"/>.

> My ideal
> world would be to have a view that is entirely described by the FXML and
> loaded by the controller via FXMLLoader. The view is described as an
> interface and the FXMLLoader would use dynamic proxy to implement that
> interface.

But that would require defining an interface to represent the view, which would be a lot of work and, in most cases, unnecessary. FXML is fundamentally dynamic in nature, whereas interfaces are static (i.e. compiled). 

Keep in mind that the primary purpose of the controller is to act as the backing logic or "code behind" for the elements defined in the document. XAML does this via partial classes, and FXML does it with a controller object, but the intent is similar.


More information about the openjfx-dev mailing list