FXMLLoader templates
Richard Bair
richard.bair at oracle.com
Thu Oct 3 08:40:22 PDT 2013
After reviewing the situation with Martin my feeling was that this API is just not ready for prime-time. In fact, I'd like to think of how FXML fits in from a more holistic perspective, meaning, it might be time to consider a different approach to loading FXML files than the way FXMLLoader was designed to be used. I've never had that settled feeling about FXMLLoader (whereas most of the functionality in FXML itself I've been quite pleased with). And as Tom mentioned, there is now a much faster alternative anyway (it just won't work as well for dynamically loaded FXML, unless you do the compilation step locally).
Richard
On Oct 1, 2013, at 12:15 AM, Martin Sladecek <martin.sladecek at oracle.com> wrote:
> After discussion with Richard, we decided to remove the template flag from FXMLLoader for 8.0.
> This API is not mature yet, due to the reasons described below and should be completely re-designed for some next release.
>
> This means that loading the same fxml multiple times will still require multiple FXMLLoader instances.
>
> Any comments?
>
> Thanks,
> -Martin
>
> On 09/20/2013 02:22 PM, Martin Sladecek wrote:
>> 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