Menu

Create a Controller

Ralph

The controller is the missing link between a view object and a JavaFX stage.

By using @FXML annotations each FX control can be injected into the controller.
The controller has to know how a view object shall be maintained.
Then it is easy for the controller to map attributes from the view object to the controls of the JavaFX stage.

Here we implement the view controller.

package de.hoppe.extra.person;

import ...

public class PersonListController<V extends VoPerson> extends DbListController<V> implements Initializable {

  @FXML
  private TableView<V> personTableView;
  @FXML
  private TableColumn<V, String> search;

  @Override
  public void initialize(URL location, ResourceBundle resources) {
    setTableView(personTableView);
  }
  ....
}

That is all to display the attribute search to the table view. The rest is done by fxDB.

One thing is missing. How does the controller know how to match entity columns and view object attributes?

Please notice the generics: V extends VoPerson. Here the controller is informed about the type of the view object. For each column in the table view the controller will try to find the matching ...Property- method in the view object. This is the reason why we have implemented the annotated ...Property- methods in the view object.

And how does the controller known what query result set shall be displayed?

[Create a Query Service] is the contents of the next page.


Related

Wiki: Create a JavaFX Stage
Wiki: Create a Query Service