FXMLLoader templates
Martin Sladecek
martin.sladecek at oracle.com
Fri Sep 20 05:22:14 PDT 2013
Hi,
I would like to discuss a 8.0 feature of FXMLLoader - the template flag.
I was introduced with this issue:
https://javafx-jira.kenai.com/browse/RT-23413, but unfortunately, it
never worked: https://javafx-jira.kenai.com/browse/RT-28121. I was
trying to fix the issue, but the whole concept of a flag for loading
templates seems hardly usable and incorrect to me and should be replaced
with something more appropriate.
The reason is the handling of root, controller and the namespace before
and after the load. Both are treated in 2 different ways. Before the
load, they are used to adjust the following load - by setting the root
(for <fx:root> tag), setting the namespace and a controller.
However, after the load, these properties (though not FX-properties) can
be used to query what was just loaded. The root of the FXML, the
namespace with all "id"s and the controller.
Now that's not very useful when you want to use template loading. My
solution for RT-28121 (when keeping the old API) is to save the
namespace after setTemplate(true) was called, using this namespace on
each load(), clearing it at the begging of load() + disallow
setController() for this mode.
But that doesn't cover all of the relevant use-cases I can think of.
Actually, without changing the API, I doubt we can support all such
use-cases.
Here's the set I'm working with:
1) setup some "template namespace", n times do { adjust namespace (based
on template namespace) , load) }
2) n times do {load, query id from namespace}
3) n times do {setController(new Controller) load }
4) n times do {load, query newly created controller}
5,6) same as 3,4 but with root
So while in 1,3 we would need to clear namespace/controller after each
load, in 2,4 we need to clear it before each load. In case 3),
forgetting to set a new controller would otherwise result in 2 instances
with the same controller.
One solution might be to split this to 2 independent calls.
setController/getLoadedController, ObservableMap getNamespace() and Map
getLoadedNamespace (unmodifiable).
Another might be a completely new class FXMLTemplate.
It might yield new pre-set FXMLLoaders that can be adjusted and loaded,
but it means generating a temporary object for each call.
Also, FXMLLoader would need to be updated, so that it's only possible to
call load() once.
Other ideas / use-cases?
Thanks,
-Martin
More information about the openjfx-dev
mailing list