You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pivot.apache.org by Greg Brown <gk...@mac.com> on 2010/07/05 21:45:59 UTC

Property binding

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

 

Re: Property binding

Posted by Greg Brown <gk...@mac.com>.
I can see some validity to that argument. On the other hand, since Pivot has another means of data binding that is better suited to the use case you describe, I think it makes sense to leave the namespace binding feature as-is and see how it ends up being used. What you describe could easily be added in a future update.

On Jul 19, 2010, at 9:26 AM, Michael Allman wrote:

> On Mon, 19 Jul 2010, Greg Brown wrote:
> 
>>>>> What about properties of properties of objects---like ${obj.prop.subprop}?  If the "obj.prop" value changes, do the binding listeners get notified?
>>>> 
>>>> No, because those listeners have indicated that the property they care about is "subprop". They don't necessarily know or care that "prop" is referred to by another object ("obj", in this case).
>>> 
>>> I can't think of a case off the top of my head where you would actually run into this situation in the current implementation.  If you can, it would help illustrate the problem.
>> 
>> I think the current implementation is valid. But just for comparison, it would be useful to know what Flex does in this case.
> 
> You have the flex-ibility (sorry, couldn't help myself) to define a "site" and a "chain" when creating bindings in code.  The "site" is the root of the bound hierarchy.  The "chain" is the sequence of properties for each of which a listener is registered.  If any property in the chain changes, the bound listener will receive a notification if the last property in the chain does in fact change.
> 
> But bindings are rarely done in code and are rarely thought out that thoroughly.  By default, in a root-property sequence "object.prop1.prop2.prop3..." any change in any of prop1, prop2, prop3, etc. will notify a listener.  I think I can give a simple example of why this is desirable.
> 
> Suppose a component binds one of its properties to the expression "person.name.first".  If first changes from "John" to "Jane" the listener will receive a notification of a change in "person.name.first" from "John" to "Jane".  If name changes from {first: "John", last: "Doe"} to {first: "Jane", last: "Doe"}, shouldn't the listener know the first name changed? Strictly speaking, the original name's "first" property didn't change---it's still "John".
> 
> Similarly, if person is reassigned from person1 to person2 and they have different first names, etc.  If this person is a data model backing a form, and the person is changed wholesale, any "first name" labels/inputs/validators/parsers/what-have-you need to know.
> 
> Cheers,
> 
> Michael


Re: Property binding

Posted by Michael Allman <ms...@allman.ms>.
On Mon, 19 Jul 2010, Greg Brown wrote:

>>>> What about properties of properties of objects---like 
>>>> ${obj.prop.subprop}?  If the "obj.prop" value changes, do the binding 
>>>> listeners get notified?
>>>
>>> No, because those listeners have indicated that the property they care 
>>> about is "subprop". They don't necessarily know or care that "prop" is 
>>> referred to by another object ("obj", in this case).
>>
>> I can't think of a case off the top of my head where you would actually 
>> run into this situation in the current implementation.  If you can, it 
>> would help illustrate the problem.
>
> I think the current implementation is valid. But just for comparison, it 
> would be useful to know what Flex does in this case.

You have the flex-ibility (sorry, couldn't help myself) to define a "site" 
and a "chain" when creating bindings in code.  The "site" is the root of 
the bound hierarchy.  The "chain" is the sequence of properties for each 
of which a listener is registered.  If any property in the chain changes, 
the bound listener will receive a notification if the last property in the 
chain does in fact change.

But bindings are rarely done in code and are rarely thought out that 
thoroughly.  By default, in a root-property sequence 
"object.prop1.prop2.prop3..." any change in any of prop1, prop2, prop3, 
etc. will notify a listener.  I think I can give a simple example of why 
this is desirable.

Suppose a component binds one of its properties to the expression 
"person.name.first".  If first changes from "John" to "Jane" the listener 
will receive a notification of a change in "person.name.first" from "John" 
to "Jane".  If name changes from {first: "John", last: "Doe"} to {first: 
"Jane", last: "Doe"}, shouldn't the listener know the first name changed? 
Strictly speaking, the original name's "first" property didn't 
change---it's still "John".

Similarly, if person is reassigned from person1 to person2 and they have 
different first names, etc.  If this person is a data model backing a 
form, and the person is changed wholesale, any "first name" 
labels/inputs/validators/parsers/what-have-you need to know.

Cheers,

Michael

Re: Property binding

Posted by Greg Brown <gk...@mac.com>.
>>> What about properties of properties of objects---like ${obj.prop.subprop}?  If the "obj.prop" value changes, do the binding listeners get notified?
>> 
>> No, because those listeners have indicated that the property they care about is "subprop". They don't necessarily know or care that "prop" is referred to by another object ("obj", in this case).
> 
> I can't think of a case off the top of my head where you would actually run into this situation in the current implementation.  If you can, it would help illustrate the problem.

I think the current implementation is valid. But just for comparison, it would be useful to know what Flex does in this case.


Re: Property binding

Posted by Michael Allman <ms...@allman.ms>.
On Fri, 16 Jul 2010, Greg Brown wrote:

>> I've finally had a chance to take a good look at this.  This looks fine 
>> for the use case it covers, that is, properties of objects which 
>> observe some kind of event listener design (don't know the details). 
>> What about properties of properties of objects---like 
>> ${obj.prop.subprop}?  If the "obj.prop" value changes, do the binding 
>> listeners get notified?
>
> No, because those listeners have indicated that the property they care 
> about is "subprop". They don't necessarily know or care that "prop" is 
> referred to by another object ("obj", in this case).

I think this discussion is premature.  I can't think of a case off the top 
of my head where you would actually run into this situation in the current 
implementation.  If you can, it would help illustrate the problem.

Cheers.

Re: Property binding

Posted by Greg Brown <gk...@mac.com>.
> I've finally had a chance to take a good look at this.  This looks fine for the use case it covers, that is, properties of objects which observe some kind of event listener design (don't know the details).  What about properties of properties of objects---like ${obj.prop.subprop}?  If the "obj.prop" value changes, do the binding listeners get notified?

No, because those listeners have indicated that the property they care about is "subprop". They don't necessarily know or care that "prop" is referred to by another object ("obj", in this case).




Re: Property binding

Posted by Michael Allman <ms...@allman.ms>.
I've finally had a chance to take a good look at this.  This looks fine 
for the use case it covers, that is, properties of objects which observe 
some kind of event listener design (don't know the details).  What about 
properties of properties of objects---like ${obj.prop.subprop}?  If the 
"obj.prop" value changes, do the binding listeners get notified?

Cheers,

Michael

On Wed, 14 Jul 2010, Greg Brown wrote:

> I moved it to the tutorials project:
>
> http://svn.apache.org/repos/asf/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/databinding/property_binding.bxml
> http://svn.apache.org/repos/asf/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/databinding/PropertyBinding.java
>
> On Jul 14, 2010, at 12:04 AM, Michael Allman wrote:
>
>> Greg,
>>
>> I get a 404 when I go to the source code URL.  Can you check it please?
>>
>> Michael
>>
>>
>> On Fri, 9 Jul 2010, Greg Brown wrote:
>>
>>> Hi all,
>>>
>>> This feature is now complete. BXMLSerializer now supports dynamic namespace binding via the syntax I suggested in my earlier email. You can see a demo here:
>>>
>>> http://ixnay.biz/pivot-demos/namespace-binding.html
>>>
>>> The source code is here:
>>>
>>> http://svn.apache.org/repos/asf/pivot/trunk/demos/src/org/apache/pivot/demos/binding/
>>>
>>> I'm pretty happy with how it turned out. Let me know what you think.
>>>
>>> G
>>>
>>> On Jul 8, 2010, at 10:40 AM, Greg Brown wrote:
>>>
>>>> FYI, I have just checked in initial support for this feature. I haven't hooked it in to BXMLSerializer yet, but you can see it in action here:
>>>>
>>>> http://svn.apache.org/repos/asf/pivot/trunk/demos/src/org/apache/pivot/demos/binding/
>>>>
>>>>
>>>> On Jul 5, 2010, at 3:45 PM, Greg Brown wrote:
>>>>
>>>>> 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
>>>>>
>>>>>
>>>>
>>>
>

Re: Property binding

Posted by Greg Brown <gk...@mac.com>.
I moved it to the tutorials project:

http://svn.apache.org/repos/asf/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/databinding/property_binding.bxml
http://svn.apache.org/repos/asf/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/databinding/PropertyBinding.java

On Jul 14, 2010, at 12:04 AM, Michael Allman wrote:

> Greg,
> 
> I get a 404 when I go to the source code URL.  Can you check it please?
> 
> Michael
> 
> 
> On Fri, 9 Jul 2010, Greg Brown wrote:
> 
>> Hi all,
>> 
>> This feature is now complete. BXMLSerializer now supports dynamic namespace binding via the syntax I suggested in my earlier email. You can see a demo here:
>> 
>> http://ixnay.biz/pivot-demos/namespace-binding.html
>> 
>> The source code is here:
>> 
>> http://svn.apache.org/repos/asf/pivot/trunk/demos/src/org/apache/pivot/demos/binding/
>> 
>> I'm pretty happy with how it turned out. Let me know what you think.
>> 
>> G
>> 
>> On Jul 8, 2010, at 10:40 AM, Greg Brown wrote:
>> 
>>> FYI, I have just checked in initial support for this feature. I haven't hooked it in to BXMLSerializer yet, but you can see it in action here:
>>> 
>>> http://svn.apache.org/repos/asf/pivot/trunk/demos/src/org/apache/pivot/demos/binding/
>>> 
>>> 
>>> On Jul 5, 2010, at 3:45 PM, Greg Brown wrote:
>>> 
>>>> 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
>>>> 
>>>> 
>>> 
>> 


Re: Property binding

Posted by Michael Allman <ms...@allman.ms>.
Greg,

I get a 404 when I go to the source code URL.  Can you check it please?

Michael


On Fri, 9 Jul 2010, Greg Brown wrote:

> Hi all,
>
> This feature is now complete. BXMLSerializer now supports dynamic namespace binding via the syntax I suggested in my earlier email. You can see a demo here:
>
>  http://ixnay.biz/pivot-demos/namespace-binding.html
>
> The source code is here:
>
>  http://svn.apache.org/repos/asf/pivot/trunk/demos/src/org/apache/pivot/demos/binding/
>
> I'm pretty happy with how it turned out. Let me know what you think.
>
> G
>
> On Jul 8, 2010, at 10:40 AM, Greg Brown wrote:
>
>> FYI, I have just checked in initial support for this feature. I haven't hooked it in to BXMLSerializer yet, but you can see it in action here:
>>
>> http://svn.apache.org/repos/asf/pivot/trunk/demos/src/org/apache/pivot/demos/binding/
>>
>>
>> On Jul 5, 2010, at 3:45 PM, Greg Brown wrote:
>>
>>> 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
>>>
>>>
>>
>

Re: Property binding

Posted by Greg Brown <gk...@mac.com>.
Hi all,

This feature is now complete. BXMLSerializer now supports dynamic namespace binding via the syntax I suggested in my earlier email. You can see a demo here:

  http://ixnay.biz/pivot-demos/namespace-binding.html

The source code is here:

  http://svn.apache.org/repos/asf/pivot/trunk/demos/src/org/apache/pivot/demos/binding/

I'm pretty happy with how it turned out. Let me know what you think.

G

On Jul 8, 2010, at 10:40 AM, Greg Brown wrote:

> FYI, I have just checked in initial support for this feature. I haven't hooked it in to BXMLSerializer yet, but you can see it in action here:
> 
> http://svn.apache.org/repos/asf/pivot/trunk/demos/src/org/apache/pivot/demos/binding/
> 
> 
> On Jul 5, 2010, at 3:45 PM, Greg Brown wrote:
> 
>> 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
>> 
>> 
> 


Re: Property binding

Posted by Greg Brown <gk...@mac.com>.
FYI, I have just checked in initial support for this feature. I haven't hooked it in to BXMLSerializer yet, but you can see it in action here:

http://svn.apache.org/repos/asf/pivot/trunk/demos/src/org/apache/pivot/demos/binding/


On Jul 5, 2010, at 3:45 PM, Greg Brown wrote:

> 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
> 
> 


Re: Property binding

Posted by Michael Allman <ms...@allman.ms>.
I've been working on a prototype but it's a big job and I've got "real" 
work to do.  I've implemented an annotation and an annotation processor 
that creates a property change dispatcher for an annotated property 
through bytecode enhancement of a setter.  It doesn't use reflection and 
it supports binding to any property, whether there's a listener defined 
for it or not.  I haven't gotten any farther than that and don't know when 
I'll resume work.

Cheers,

Michael

On Mon, 5 Jul 2010, Greg Brown wrote:

> 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
>
>
>