Do two different stores share the same model?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Do two different stores share the same model?

voger
I have this code https://gist.github.com/voger/8595dd76bbc6c5753922

In line 30 I set a store of type qx.data.store.Rest
In line 31 I set a store of type qx.data.store.Json

In lines 46 to 53 I set bindings the qx.data.store.Rest to a
qx.ui.embed.Html widget and the qx.data.store.Json to a
qx.data.controller.List

The problem is that when I run the code, when the widget appears on the
screen I get this error

020996 Assertion error! Invalid incoming value for property 'html' of
class 'qx.ui.embed.Html': Expected value to be a string but found
qx.data.model.id"name[3079-0],qx.data.model.id"name[3080-0],qx.data.model.id"name[3081-0]!

When I disable the binding to the lines 47 to 53 I get no error in
console. It seems like the bindings use the same model which doesn't
make sense.

After that it works normally without error messages until I close and
open the widget again.

I guess I could use plain event listeners for this task but I would like
to know why the code above doesn't work.

------------------------------------------------------------------------------
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: Do two different stores share the same model?

John Spackman-3
The bind is not working because model is not a string, and whatever property you bind to qx.ui.embed.Html.html must be a string.

qx.data.store.Rest “marshals” the JSON result into it’s “model” property using qx.data.marshal.Json - what that means is that given a JSON data structure like:


        [ { name: “alpha”, id: 1 }, { name: “bravo”, id: 2 } ]

It will create a class on the fly which looks approximately like:

Qx.Class.define(“qx.data.model.id\”name”, {
  extend: qx.core.Object,
  properties: {
    name: {
      check: “String”,
      event: “changeName”
    },
    id: {
      check: “Number”,
      event: “changeId”
    }
  }
});

And then create two instances of the new class and stick them in an array.  

This is obviously useful for binding to Qx objects, and when using the Rest.* apis that’s normally what you want but it means that you’re trying to set qx.ui.embed.Html.html’s property to an object (maybe a qx.data.Array of “qx.data.model.id\”name” objects in this case).

If you want the raw output, try this:

this.__tos.addListener(“getSuccess”, function(evt) {

  var data = e.getData();
  this.__tosWidget.setHtml(data||””);
}, this);

John




On 22/09/2015 20:50, "voger" <[hidden email]> wrote:

>I have this code https://gist.github.com/voger/8595dd76bbc6c5753922
>
>In line 30 I set a store of type qx.data.store.Rest
>In line 31 I set a store of type qx.data.store.Json
>
>In lines 46 to 53 I set bindings the qx.data.store.Rest to a
>qx.ui.embed.Html widget and the qx.data.store.Json to a
>qx.data.controller.List
>
>The problem is that when I run the code, when the widget appears on the
>screen I get this error
>
>020996 Assertion error! Invalid incoming value for property 'html' of
>class 'qx.ui.embed.Html': Expected value to be a string but found
>qx.data.model.id"name[3079-0],qx.data.model.id"name[3080-0],qx.data.model.id"name[3081-0]!
>
>When I disable the binding to the lines 47 to 53 I get no error in
>console. It seems like the bindings use the same model which doesn't
>make sense.
>
>After that it works normally without error messages until I close and
>open the widget again.
>
>I guess I could use plain event listeners for this task but I would like
>to know why the code above doesn't work.
>
>------------------------------------------------------------------------------
>_______________________________________________
>qooxdoo-devel mailing list
>[hidden email]
>https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel



------------------------------------------------------------------------------
Monitor Your Dynamic Infrastructure at Any Scale With Datadog!
Get real-time metrics from all of your servers, apps and tools
in one place.
SourceForge users - Click here to start your Free Trial of Datadog now!
http://pubads.g.doubleclick.net/gampad/clk?id=241902991&iu=/4140
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: Do two different stores share the same model?

voger
Thanks. This explains the error message I was seeing. I thought I was
going crazy. The qx.data.store.Rest was getting a string from the server
while the qx.data.store.Json was coincidentally getting a JSON response
in the form [{id: "en", name: "English"}]. Now imagine my confusion.

Finally the problem was that I was constructing the "site/tos/{lang}"
URI on display, before the variable {lang} was available so the
qx.ui.embed.Html tried to use the default model. I changed the listener

from:

this.addListener("appear", function() {
//stuff here
},this);

to:

languagesStore.addListener("loaded", function() {
//stuff here
},this);

and now it works.

On 23/09/2015 10:25 πμ, John Spackman wrote:

> The bind is not working because model is not a string, and whatever property you bind to qx.ui.embed.Html.html must be a string.
>
> qx.data.store.Rest “marshals” the JSON result into it’s “model” property using qx.data.marshal.Json - what that means is that given a JSON data structure like:
>
>
> [ { name: “alpha”, id: 1 }, { name: “bravo”, id: 2 } ]
>
> It will create a class on the fly which looks approximately like:
>
> Qx.Class.define(“qx.data.model.id\”name”, {
>    extend: qx.core.Object,
>    properties: {
>      name: {
>        check: “String”,
>        event: “changeName”
>      },
>      id: {
>        check: “Number”,
>        event: “changeId”
>      }
>    }
> });
>
> And then create two instances of the new class and stick them in an array.
>
> This is obviously useful for binding to Qx objects, and when using the Rest.* apis that’s normally what you want but it means that you’re trying to set qx.ui.embed.Html.html’s property to an object (maybe a qx.data.Array of “qx.data.model.id\”name” objects in this case).
>
> If you want the raw output, try this:
>
> this.__tos.addListener(“getSuccess”, function(evt) {
>
>    var data = e.getData();
>    this.__tosWidget.setHtml(data||””);
> }, this);
>
> John


------------------------------------------------------------------------------
Monitor Your Dynamic Infrastructure at Any Scale With Datadog!
Get real-time metrics from all of your servers, apps and tools
in one place.
SourceForge users - Click here to start your Free Trial of Datadog now!
http://pubads.g.doubleclick.net/gampad/clk?id=241902991&iu=/4140
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel