FXML expression binding scope

Greg Brown greg.x.brown at oracle.com
Mon May 21 09:50:28 PDT 2012


> I am using the following fxml to bind a label's managed property to its visible property:
> 
> <Label fx:id="label" text="more" managed="${label.visible}"/>
> 
> It would be nice if the following would work also...
> 
> <Label fx:id="label" text="more" managed="${visible}"/>
> 

> ...so that I don't have to repeat the "local" fx:id (and specify one in the first place). Any thoughts about this?

This would involve introducing the notion of "element scope", which is possible but seems like a lot of work for what (in my opinion) is an edge case. My guess is that most bindings will be to properties of other elements, not properties of the declaring element itself. It would also be confusing since "${visible}" already has a defined meaning (see below).

> Also, what does "${visible}" actually bind to?

It binds to the value of "visible" in the document's namespace. For example, you might define a script block that defines a "visible" variable:

<fx:script>
var visible = false;
</fx:script>

Then later you could bind to this variable:

<Label fx:id="label" text="more" managed="${visible}"/>

Whenever the value of the "visible" variable changes, the bindings will be updated.

G



More information about the openjfx-dev mailing list