Hello Jean-Noel,

Am 28.04.2009 um 16:11 schrieb Jean-Noël Rivasseau:

Hi Martin and thanks for the answers, which result in more questions :)

Hi,

I had a look at the data binding framework of Qooxdoo which looks great and promising. I have a question though, it looks like there is some support for pulling data out of a data source and then binding it to a view widget via the Json store class, then the controllers. But is the other direction possible, eg, detect a change to the model which was bound to a widget, and automatically make a server call back to the web server to update the data source (probably a relational DB).

Sure that is possible. But we dont have a store ready for it yet. You can see an example for writing data back from the model in the gears demo in the demo browser. Specially for such a scenario, a bubble event mechanism has been introduced to the generated models. That way you dont have to listen to every single value in the model.
You can take a look at the API or the code to see how it works: 
http://demo.qooxdoo.org/devel/apiviewer/#qx.data.marshal.MEventBubbling

I've looked at this and MEventBubbling seems the way to go. However I am not quite sur how to use it. In the Gears demo you just create a class from some result JSON data via the marshaller and add an option so that the generated class automatically implements this mechanism. How can I do this with one of my own class? I can add the MEventBubbling mixin, but the API say:

If you want to use this in your own model classes, be sure that every property will call the #_applyEventPropagation function on every change.

How do I do this? Manually writing my own setter that will call this function? Doesn't it defeat the purpose of having this mechanism? I mean, if I have to write all my setters functions, I may as well make them call the final method that will update the model back into the server via a server call.

If you want to use the MEventBubbling mixin you have to call that method on every change. The way i did it in the generated classes is to use this method (__applyEventPropagation) as apply on every property, which you can add easily with the apply key in the property definition. If you already have an apply method, just call the method in your apply and you should be fine. The advantage of using he bubbling is that the events will bubble up the object hierarchy. Thats an huge advantage to implementing the actual function code in the objects.


Of course, such an automatic change may cause some problems, so it should be configurable I guess (only update when the user presses a specific button for instance). I guess I could also manually code something up pretty quickly thanks to Qooxdoo events launched on the model (writing code on _apply for instance), but I was wondering, has anyone thought of this functionality? It would be nice if it were implemented in a way which makes sense.

Sure we have thought of that. Its on our todo list to get something in that direction out of the box.

Ok, I will wait until you are a bit more advanced on this then.

Second question, because of cross domain concerns, I am using the script implementation when making server calls. Is this option available when using the Json store? Eg, is it possible to use the current Json store with a server call via a script transport implementation.

It is possible but not right out of the box. Just take a look at the twitter or flicker demo in the demobrowser. Each of them uses a special store implementation and a other object for transport (both use JSONP). I guess exactly the same way you could change the transport layer.

Ok, haven't looked at that yet but I will soon.

Third question, the docs about using a delegate for data-binding don't mention how to actually use the delegate with the controller ?! Eg, once you wrote your delegate, how do you hook it up in your controller?

The lists and tree controller support the delegation mechanism. Both of them have a property called delegate where the created delegate object should be set via setDelegate(...). Thats all. :)

Ha ok. I only looked at the simple Object controller and it did not have that property, thus my confusion. So you cannot use a delegate with the Object controller? Why? (I currently only use Object controllers).

The delegate offers three methods to manipulate the creation of the widgets of the controller and a fourth method for filtering the content. The object controller does not create objekts like for example the list controller creates listitems. Also the filtering could be a problem on the object controller. I dont see how to filter singe values. Therefore, the whole delegate would not offer additional functionality to the object controller and has been due to that left out.


Last question, I am interested in the hierarchy data binding ("A more advanced feature of the single value binding is to bind a hierarchy of properties to a target property.")
However, conceptually, with a complex model, there could be more than one child for the parent object. Eg, how would you adapt the current following code to a case where a has a "b" node but also a "c" node with a different property? Does not look possible currently...
var a = new Node("a");      // set the name to „a“

var b = new Node("a");      // set the name to „b“
a.setChild(b);


// bind the property to a labels content
a.bind("child.name", label, "content");


The binding always goes down from one property to another. If you change something in the chain, the binding tries to get down the new property chain. If thats not possible, the target property will be reseted. I did recently a presentation on the whole data binding layer. Perhaps the slides could make the concept of the "deep binding" better understandable. You can find the slides on my slideshare account. http://www.slideshare.net/wittemann/data-binding-in-qooxdoo

For this I think you did not really understand my question. Let's imagine that we have an object myZoo of the class Zoo. Zoo has two properties lion, and elephant.

You are right, but now i get your question. ;)


How could I bind myZoo.lion.age to a GUI widget (like a slider), but at the same time bind myZoo.elephant.age to another slider widget?

If I do myZoo.setChild(lion); then I guess it has no sense writing myZoo.setChild(elephant) because I already declared a child - but myZoo in effect has multiple children!

In the
myZoo.bind("child.age", slider, "value");


call, which child will be used?

Your example itself is some kind of misleading. If you have a myZoo object which does have two properties (lion and elephant) you will have to use this properties to set the objects. So myZoo.setChild adresses a third property called child. If you want to set the lion property, you have to use myZoo.setLion(lion) and the same for the elephant: myZoo.setElephant(elephant). That way, you have two properties set to two different objects. This could be used in the binding as well:

myZoo.bind("lion.age", slider1, "value);
myZoo.bind("elephant.age", slider2, "value");

If you want to use only one property and swith the animals on runtime, you can du that with the mentioned child property (or call is something else, it doesn't matter).

myZoo.bind("child.age", slider, "value");

myZoo.setChild(lino);               // lions age is bound to the slider
myZoo.setChild(elephant);      // elephants age is bound to the slider

So it depends on what you want to achieve.


Regards,
Martin


Do you see what I mean?

Cheers

Jean-Noel

------------------------------------------------------------------------------
Register Now & Save for Velocity, the Web Performance & Operations
Conference from O'Reilly Media. Velocity features a full day of
expert-led, hands-on workshops and two days of sessions from industry
leaders in dedicated Performance & Operations tracks. Use code vel09scf
and Save an extra 15% before 5/3. 
http://p.sf.net/sfu/velocityconf_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

------------------------------------------------------------------------------
Register Now & Save for Velocity, the Web Performance & Operations 
Conference from O'Reilly Media. Velocity features a full day of 
expert-led, hands-on workshops and two days of sessions from industry 
leaders in dedicated Performance & Operations tracks. Use code vel09scf 
and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to