[REVIEW] Make controller instantiation customizable

Greg Brown greg.x.brown at oracle.com
Mon Dec 19 09:01:28 PST 2011


OK, thanks. I believe I understand the value now. This would allow a caller to apply some type checking on values that are used to pre-populate a loader's namespace, and would also allow a caller to pass arguments to an include (something that isn't currently supported). Seems particularly useful when creating bindings, as in your example below. Not sure what other uses there might be.

However, I see this as something that would complement the existing controller support rather than replace it. What do others think?

G

On Dec 19, 2011, at 11:36 AM, Gaja Sutra wrote:

> 
>>> Having <?param?> allow multiple arguments to this constructor of object represented by FXML. 
>> OK. How you might expect to use this feature in practice? I.e. what arguments might you want to pass to the FXML? How would you expect to pass them? How would you expect them to be used/accessed by the document and/or its associated logic? A simple use case with sample pseduo-code would be very helpful.
> First example (because I have found a link to documentation), in case of multiples forms, a typical usage can be passing an instance of a Java object per form, like that (in XML world):
> http://www.w3.org/TR/xforms/#concepts-multiple
> 
> In a simple and generic case like their poll near the form, I think the poll will even be an included FXML file and the code inclusion will be better with a specified parameter:
> <fx:include source="poll.fxml">
>    <fx:with-param name="pollProcessor" value="${...}"/>
> </fx:include>
> 
> // file "poll.fxml"
> ...<?import ...?>
> <?param name="poll" type="PollProcessor"?>
> <*Pane> <!-- no fx:controller="" -->
>     <Slider value="${poll.opinion}" />
>     <Button onAction="#poll.process"/>
> </*Pane>
> In this case, the parameter is probably strictly replacing the controller of imported FXML, but I think code will be more readable because link between FXML and the poll processor will be made in one and only one method (the method called in //fx:with-param/@value). If we have a fx:controller attribute, it will give the absolute class name, but only the ControllerFactory will add, after creating instance, the unique identifier of the form evaluated by the poll.
> 
> ---
> 
> For me, when editing a document, I would expect uses like having side-by-side near-independent views when user creates a new link, by example when he creates an internal reference in a document:
> current text/data editing, where user is inserting a reference
> possibles targets for reference (items in table of contents or in bibliographic table)
> I would expect, by example, that possibles targets of reference will be a parameter and using it like that:
> <TableView items="${paramBibliographicEntries}" />
> ----
> [My principles]: Most of my use-cases will be defined by extracting from FXML controller instances of objects not using JavaFX objects. If a method receive an *Event, it will go in FXML controller. When multiples data fields of controller are correlated and used together (like the model of a form), this becomes a class without references to JavaFX classes; for manipulating the instance of the class, I prefer writing declarative code (<?param?> in FXML) to imperative code (getter in FXML controller in Java).
> ---
> For passing parameters to FXMLLoader, I suggest allowing the two possibilities: varargs (sufficient for me) and map (given many people probably prefer named parameter).
> NB: Varargs contains values of params following order of <?param name="" type=""?> processing instructions ignoring pseudo-attribute name (then used only in FXML files). Map, more precisely Map<String, Object>, simply associate object to parameter using same name.
> 
> Hoping it can be useful.
> Thanks,



More information about the openjfx-dev mailing list