Another question that seems to come up fairly often is - "does Pivot support
dynamic data binding like Flex?" Historically, the answer we have given is,
"no, Pivot's data binding support is based on a load/store model that maps well
to client/server applications such as REST clients."
However, there are cases where Flex-like data binding can be useful. Given the
recent updates to BXMLSerializer, I think it may now be relatively
straightforward to implement. It may also be a good way to support dynamically
updatable styles, since style values are simply page variables, just like
everything else. Consider the following example:
<Label text="$text">
<styles color="$styles.color"/>
</Label>
When loaded, the text property of the label will be set to the value of the
"text" variable, and the color style will be set to the value of the
"styles.color" variable. It may be possible to (fairly easily) extend the
syntax of BXML such that something like the following would cause the text
property and color style to automatically reflect changes to the source
variable:
<Label text="${text}">
<styles color="${styles.color}"/>
</Label>
Basically, this syntax (or something like it) would be a cue to the serializer
to register a change listener on the given variable and propagate any changes
to the bound property.
I haven't prototyped it, so I'm not sure what hidden gotchas we might run into,
but I think it could work. The primary trick will be in determining the type of
the parent object and registering an appropriate listener. For example, if
"styles" in the above example is a Map, we would register a MapListener on the
"styles" object to be notified of changes to the "color" variable. If it is a
bean, we'd need to use something like the BeanMonitor class used in the
Component Explorer demo. That means we'd probably want to move that class to
org.apache.pivot.beans (which might be worth doing anyways).
Let me know what you think. If there is sufficient interest, I may try to get
it working.
G