CDI Callback<TableColumn, TableCell> cellFactory - from FXML

How to get a full managed JavaFX-element declared in the fxml-file?
Let´s say we have something like the following:
This looks like a normal definition of a TableView with some cell-factories. The intressting part is the instantiating of the cellFactory elements. They are created from the JavaFX part. How to get them as full managed bean?
Based on my blog entry about (CDI-JavaFX bootstrapping) I wanted to have full cdi managed JavaFX elements but defined in my fxml-file.
How to get this with a ComboBoxCell you can see here (cdi comboboxcell how to reduce 80 of code)
The aproach was to define an element that is able to associate itself as CellFactory. Only two line of code are used during the init - phase:
BUT: the definition inside the fxml-file is
You only could (implicit)define a normal CellFactory, because the creation of this element would be done by JavaFX.
Now I want to write a more precise fxml file.
Now you could see, the CellFactory is well defined. Here an EditingAutoCompleteStringCellFactory. This is an element with injected autocomplete functions/data.
Inside this class you can use all cdi features.
The missing part is: How to get this as managed instance?
The short answer is.. make it managed by yourself ;-)
Let´s say the controller is a managed instance, you can get the BeanManager with
Now I started to get during the init-phase the right column
After you found the right column, start with the CDI-stuff Ready.. but this code is not nice... and done for every column this is toooooo much code.
So I started to reduce it.
- reducing the generics..
- getting the class from the instance itself
Done.. OK, this is short and easy.. and you can do it for every column..
or more generic...
Now you can use CDI-managed elements as CellFactories and define them inside your fxml.
Nice, Managed and TypeSave

Kommentare

Beliebte Posts