Hello again,

So I'm having the following problem with qooxdoo list controller: I've
got a list of items in a model and I want them to be editable. Each
item in the model has a set of properties, for example name and
description. I display the items using a qooxdoo qx.ui.form.List class
to display the list of items, and a qx.data.controller.List to link
the model to the view.

Also, I use a custom delegate with the mentioned list controller, so
that it creates list items of my own custom widget type. I use a
composite item with a grid layout and some textfields that allows the
user to see and change the properties of the items in the model. In
order to link those properties of the model with the properties of my
custom list item, I use bindProperty in the controller delegate, as
qooxdoo documentation suggests, something like:

    bindItem : function(controller, listItem, id)
    {
      controller.bindProperty("name", "name", null, listItem, id);
      controller.bindProperty("description", "description", null, listItem, id);
   }

The thing is, I want not only the changes in the model to be reflected
in my view, but also I want the view to modify the model. So the
binding must be done two ways:

    bindItem : function(controller, listItem, id)
    {
      controller.bindProperty("name", "name", null, listItem, id);
      controller.bindProperty("description", "description", null, listItem, id);

      controller.bindPropertyReverse("name", "name", null, listItem, id);
      controller.bindPropertyReverse("description", "description",
null, listItem, id);
   }

And that is the root of my problem: this works nicely until someone
removes an item from the model. Why, you might ask? Well, first we
need to take a look at how binding works here. When create an Item,
the createItem()) function in the controller delegate is called, and
it creates an instance of my custom list item. Then the binding is
done, calling to bindItem().

The previously shown bindItem() function first setups a binding from
properties in the model to properties in my widget. When this is done,
the properties in the widget get synced with the ones in the model,
and thus the data of the model is shown in the widget. Then, the
bindPropertyReverse() calls do the binding the other way, so that when
data is changed in the widget, it's updated in the model.

What happens when an item is deleted from the model? IF you've got
first an item with name property with value "Foo" and a second item
with name property with value "Bar" and you remove the first one from
the model, the controller notices that, and removes the second widget.
Automagically thanks to the binding to array positions that qooxdoo
provides, the first widget that was showing the "Foo" element will
continue showing the first element of the array, that now happens to
be "Bar" because "Foo" has just been removed.

The problem being, because of the bindPropertyReverse() calls, the
widget's name property has still the value "Foo", and it syncs that
value with the one in the model (with at the moment holds the value
"Bar"). Here is a scheme:

situation 0:

widget1.name <> model[0].name ("Foo")
widget2.name <> model[1].name ("Bar")

model = [
{id : 123, name : "Foo"},
{id : 124, name : "Bar"},
]

situation 1:

widget1.name <> model[0].name ("Foo")

model = [
{id : 124, name : "Bar"}, <<<<<< Foo (item with id = 123) has been removed
]


situation 2:

widget1.name <> model[0].name ("Foo")

model = [
{id : 124, name : "Foo"},
]

Has anyone else been already in this situation? What am I doing wrong?
What are the possible solutions or ideas to work around this?

Regards,
   Eduardo Robles Elvira.
---
Artesanos del Software.

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to