Hello Christian, 
You remember some posts ago i told you i think of the problem with the mix
of the ui and data model and i come up with a solutions later. 
I have thought about it and also fixed a bit in the list controller and
finally have an alternative:

// create the ui data
var uidata = {
"article": {"icon":"icon\/16\/actions\/document-new.png","label":"Article"},
"book": {"icon":"icon\/16\/actions\/document-new.png","label":"Book
(Monograph)"},
"chapter": {"icon":"icon\/16\/actions\/document-new.png","label":"Book
Chapter"}}; 

// extract the models to an separate array
var modelData = [];
for (var m in uidata) {
  modelData.push(m);
}
var model = qx.data.marshal.Json.createModel(modelData,true);

selectBox = new qx.ui.form.SelectBox(); 

var controller = new qx.data.controller.List(null, selectBox); 
controller.setIconPath("");
controller.setLabelOptions({converter: function(value) {
  return uidata[value].label;
}});
controller.setIconOptions({converter: function(value) {
  return uidata[value].icon;
}});
controller.setModel(model); 

this.getRoot().add(selectBox);

this.debug("Selected Model: " + selectBox.getModelSelection().getItem(0));

As you can see if you run this code in the playground (trunk) you get the
value as modelSelection as expected and the selectbox will also be filled as
expected.
What do you think of such a solution?

Best,
Martin


panyasan wrote:
> 
> 
> 
> MartinWittemann wrote:
>> 
>> Hello Christian,
>> 
>> thanks for giving it a try. Sure your first raised point is a bug and i
>> have just forgotten to include a check. Its fixed already. 
>> The point with the wrong preselection is a bit more complicated.
>> With the (formally not working) setModel, you achieve the creation of the
>> binding and with that, the initialization of the form. This
>> initialization searches for "book" as model, which does not exist because
>> you haven't specified the converters yet. And as the select box is in the
>> selection mode "one", it has to select something which is the first
>> element. That set invokes the setting of the data in the form model.
>> Specifying the converters and adding the model in that order does the
>> job.
>> Regards,
>> Martin
>> 
>> 
> 
> Hi Martin,
> 
> it works like a charm! Thanks again for your quick reaction. Three cheers
> to the qooxdoo team ! ;-)
> 
> If you leave out the first  setModel now, the code is good for the demo
> browser, if you want to include it as a demonstration. I haven't tested it
> for RadioGroup - but it should work just the same. Maybe that would be
> worth a test, and then both thread and bug can be considered closed.
> 
> Best,
> 
> Christian
> 
> 
> 

-- 
View this message in context: 
http://n2.nabble.com/How-to-use-data-binding-for-a-SelectBox-which-is-intended-for-single-selection-tp3656721p3710820.html
Sent from the Q&A (solved) mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
qooxdoo-devel mailing list
qooxdoo-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to