Proposal for improving nested controller interaction in JavaFX 2.2

Greg Brown greg.x.brown at oracle.com
Wed Feb 22 07:51:14 PST 2012


> now that I think about it, I wonder if it might make more sense to map nested controller instances directly to including controller fields, like we do with namespace values.

FYI, I have prototyped this and I think it works well. Here's what my primary scene controller looks like now:

public class PrimarySceneController extends Controller {
    @FXML private Scene scene; // the scene associated with this controller
    @FXML private Scene dialogScene; // the dialog scene
    @FXML private DialogSceneController dialogSceneController; // the dialog scene's controller
    @FXML private ChoiceBox<Contact> contactChoiceBox; // choice box of contacts to edit
    
    …
    
    @FXML
    protected void handleEditButtonAction() {
        // Get the selected contact
        Contact contact = contactChoiceBox.getSelectionModel().getSelectedItem();
        
        // Populate the dialog with the contact information
        dialogSceneController.setContact(contact);
        
        // Show the dialog
        Stage dialogStage = new Stage();
        dialogStage.setScene(dialogScene);
        dialogStage.initOwner(scene.getWindow());
        dialogStage.initModality(Modality.APPLICATION_MODAL);
        dialogStage.show();

        …
    }
}

The controller for the include is automatically mapped by the loader to the dialogSceneController field, so it is typed and readily available in my button's action handler.

G



More information about the openjfx-dev mailing list