Need help with Models please !!!!

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

Need help with Models please !!!!

jwhitten


Hello,

Sorry for posting this again. But I really need some help please! I have been banging my head on this for a couple of days now, and I'm completely stuck!!!


I have set up a form and rpc object and have it all working splendidly. When the Save button is pressed on the form, it calls "_handleSubmit" which sets up the RPC params and then calls the RPC function. The "getService" function simply returns the name of the "service" I want to call on the back-end. (Yes, I know I'm using RPC _sync_... :-) Here is a brief snippet from my code. (I don't think an entire app is necessary to understand my question. If it is, I'll cruft something up and post it again.)


                _callRpcSync : function(service, url, params) // synchronous model
                {
                        var rpc = new qx.io.remote.Rpc(url, service);

                        try {
                                var results = rpc.callSync(service, qx.util.Serializer.toUriParameter(params));
                                return results;
                                }
                        catch (exc) {
                                qx.core.Init.getApplication().debug("RPC-SYNC Exception: " + exc);
                                }
                },

                _handleSubmit : function(e)
                {
                        var item = e.getData();
                        var url = "http://myUrl_blahblah";
                        var service = this._getService(item);
                        this._callRpcSync(service, url, item.getModel());
                }


So, the "item.getModel()" part has the data from the form elements in it. Like I said before, this works, no issues. What I want to do that I'm having problems with, is I want to INJECT a couple of additional items into the model just before I send it off to the RPC call. Something like this:

                _handleSubmit : function(e)
                {
                        var item = e.getData();
                        var url = "http://myUrl_blahblah";
                        var service = this._getService(item);
                        var model = item.getModel();
                        ...SOMEHOW_ADD( { crudMode: "new", crudName: "myName" } )_TO_MODEL...
                        this._callRpcSync(service, url, item.getModel());
                }


I've tried doing this just about every way I can think of. I've combed the Internet for hours and hours and read every snippet I can find on the Qooxdoo list that even remotely seems relevant, and nothing I try seems to work. I can create an array object, merge it with the model and get the NEW items but not the model items, even though they seemed to have merged. I can merge the MODEL items with the new items and get the MODEL items, but not the new items. I've tried half a dozen different things-- this seems like it should be such a SIMPLE thing to do... but nothing works!

Can somebody help me please?

THANKS!!!

John
Reply | Threaded
Open this post in threaded view
|

Re: Need help with Models please !!!!

Jim Hunter
If that really is your code, then it won't matter what you do before the _callRpcSync method since you are still passing in the getModel() param, not the one you are trying to create.

I assume that getModel() returns a JSON object. If so, try this code:

                _handleSubmit : function(e)
                {
                        var item = e.getData();
                        var url = "http://myUrl_blahblah";
                        var service = this._getService(item);
                        var model = item.getModel();
                        model["crudeMode"] = "new";
                        model["crudeName"] = "myName";
                        this._callRpcSync(service, url, model); // you must change this line!!!
                }


Hope this helps.

Jim

On Tue, Oct 9, 2012 at 7:46 PM, jwhitten <[hidden email]> wrote:


Hello,

Sorry for posting this again. But I really need some help please! I have
been banging my head on this for a couple of days now, and I'm completely
stuck!!!


I have set up a form and rpc object and have it all working splendidly. When
the Save button is pressed on the form, it calls "_handleSubmit" which sets
up the RPC params and then calls the RPC function. The "getService" function
simply returns the name of the "service" I want to call on the back-end.
(Yes, I know I'm using RPC _sync_... :-) Here is a brief snippet from my
code. (I don't think an entire app is necessary to understand my question.
If it is, I'll cruft something up and post it again.)


                _callRpcSync : function(service, url, params) // synchronous
model
                {
                        var rpc = new qx.io.remote.Rpc(url, service);

                        try {
                                var results = rpc.callSync(service,
qx.util.Serializer.toUriParameter(params));
                                return results;
                                }
                        catch (exc) {

qx.core.Init.getApplication().debug("RPC-SYNC Exception: " + exc);
                                }
                },

                _handleSubmit : function(e)
                {
                        var item = e.getData();
                        var url = "http://myUrl_blahblah";
                        var service = this._getService(item);
                        this._callRpcSync(service, url, item.getModel());
                }


So, the "item.getModel()" part has the data from the form elements in it.
Like I said before, this works, no issues. What I want to do that I'm having
problems with, is I want to INJECT a couple of additional items into the
model just before I send it off to the RPC call. Something like this:

                _handleSubmit : function(e)
                {
                        var item = e.getData();
                        var url = "http://myUrl_blahblah";
                        var service = this._getService(item);
                        var model = item.getModel();
                        ...SOMEHOW_ADD( { crudMode: "new", crudName:
"myName" } )_TO_MODEL...
                        this._callRpcSync(service, url, item.getModel());
                }


I've tried doing this just about every way I can think of. I've combed the
Internet for hours and hours and read every snippet I can find on the
Qooxdoo list that even remotely seems relevant, and nothing I try seems to
work. I can create an array object, merge it with the model and get the NEW
items but not the model items, even though they seemed to have merged. I can
merge the MODEL items with the new items and get the MODEL items, but not
the new items. I've tried half a dozen different things-- this seems like it
should be such a SIMPLE thing to do... but nothing works!

Can somebody help me please?

THANKS!!!

John



--
View this message in context: http://qooxdoo.678.n2.nabble.com/Need-help-with-Models-please-tp7581630.html
Sent from the qooxdoo mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel


------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: Need help with Models please !!!!

jwhitten
In reply to this post by jwhitten
Yes, I know. Apologies. I saw that after I posted it. I pulled a block of code from an earlier revision to show, which was still using "item.getModel()". However, in the code I've been having problems with, I use model-- as in: "var model = item.getModel()".

Reply | Threaded
Open this post in threaded view
|

Re: Need help with Models please !!!!

jwhitten

Here it is corrected:

                _handleSubmit : function(e)
                {
                        var item = e.getData();
                        var url = "http://myUrl_blahblah";
                        var service = this._getService(item);
                        var model = item.getModel();
                        ...SOMEHOW_ADD( { crudMode: "new", crudName: "myName" } )_TO_MODEL...
                        this._callRpcSync(service, url, model);
                }
Reply | Threaded
Open this post in threaded view
|

Re: Need help with Models please !!!!

N. Schröder
Hi John,

have you tried to use hidden items, e. g. "crudMode" and "crudName" as part of the model but not being displayed in the form? This way you could do something like this:

var model = qx.data.marshal.Json.createModel(item.getModel());
model.setCrudMode("new");
model.setCrudName("myName");

I'm neither a model nor a form expert but I recently solved a very similar task in the described way.

HTH,

  Norbert

jwhitten wrote
Here it is corrected:

                _handleSubmit : function(e)
                {
                        var item = e.getData();
                        var url = "http://myUrl_blahblah";
                        var service = this._getService(item);
                        var model = item.getModel();
                        ...SOMEHOW_ADD( { crudMode: "new", crudName: "myName" } )_TO_MODEL...
                        this._callRpcSync(service, url, model);
                }
Reply | Threaded
Open this post in threaded view
|

Re: Need help with Models please !!!!

jwhitten
Yes, I did think of that, and it would "solve" my immediate situation, but I don't think it would work well for my larger goal of building a "Generic" form/crud manager that I can inherit (extend) from. What I'd like to do is set properties in the Generic object to manage those various common submission, house-keeping, setup and other "out-of-band" (i.e. out of the model data) issues, and then inject them into the param set just prior to submitting them to the back-end. So in essence, you'd do something like this  (this is pseudo-code, I'm typing it on the fly as I write):


my new class ("blah blah crud MyShinyObject")

        extends "blah blah crud Generic"
        ...

        properties :
        {
              crudMode : { init: null },
              crudName: { init: null}
        }
        ...

        construct : function()
        {
               this.base(arguments);

               this.setCrudMode("new");
               this.setCrudName("MyShinyObject");

               ...
        }


Then in the Generic object it's extended from, there's something like:

       members :
       {
              _handleSubmit : function(e)
              var item = e.getData();
              var service = this._getService(item);
              var model = item.getModel();

              __SOMEHOW_ADD_( this.getCrudMode(), this.getCrudName() )_TO_MODEL__
             
              this._callRpcSync(service, this.getUrl(), model);
       }

That way, all of the heavy lifting is handled in the Generic object and all the subclassed object has to do is set the crud parameters, set up the form and its associated model, and the rest is auto-magically handled by the Generic class object.

This would cause the params to contain:

   {
         foo: "whatever",
         bar: "something else",
         crudMode: "new",
         crudName: "myShinyObject"

         ...
   }

Even more ideally, I could prepent underscores or something to the names so they would obviously be out-of-band parameters. But that's a secondary issue.

I don't really care how the params get there. Probably the best, easiest and clearest way would be to somehow convert the form model (values) into a key-value pair array (map? in JS parlance??), add the extra parameters to that, and then submit it to the RPC object for submission. But I can't figure out how to convert the model into an array either.

There doesn't appear to be any clear path from here to where I want to go. The manual doesn't seem to help, nor any of the comments I've been able to find on the net or Stack Overflow.


Thanks for helping me with this, I appreciate it!

john

Reply | Threaded
Open this post in threaded view
|

Re: Need help with Models please !!!!

Jim Hunter
Did you not look at the solution I posted? It should solve your issue. You are simply working with JSON, it's easy to add objects to your JSON as I presented in my solution. Please go back and re-read it. And if it didn't work, please tell me wny. I do this sort of stuff all the time. I compose JSON to send to the server for all my calls.

Jim


On Wed, Oct 10, 2012 at 8:51 AM, jwhitten <[hidden email]> wrote:
Yes, I did think of that, and it would "solve" my immediate situation, but I
don't think it would work well for my larger goal of building a "Generic"
form/crud manager that I can inherit (extend) from. What I'd like to do is
set properties in the Generic object to manage those various common
submission, house-keeping, setup and other "out-of-band" (i.e. out of the
model data) issues, and then inject them into the param set just prior to
submitting them to the back-end. So in essence, you'd do something like this
(this is pseudo-code, I'm typing it on the fly as I write):


my new class ("blah blah crud MyShinyObject")

        extends "blah blah crud Generic"
        ...

        properties :
        {
              crudMode : { init: null },
              crudName: { init: null}
        }
        ...

        construct : function()
        {
               this.base(arguments);

*               this.setCrudMode("new");
               this.setCrudName("MyShinyObject");*
               ...
        }


Then in the Generic object it's extended from, there's something like:

       members :
       {
              _handleSubmit : function(e)
              var item = e.getData();
              var service = this._getService(item);
              var model = item.getModel();

              *__SOMEHOW_ADD_( this.getCrudMode(), this.getCrudName()
)_TO_MODEL__*

              this._callRpcSync(service, this.getUrl(), model);
       }

That way, all of the heavy lifting is handled in the Generic object and all
the subclassed object has to do is set the crud parameters, set up the form
and its associated model, and the rest is auto-magically handled by the
Generic class object.

This would cause the params to contain:

   {
         foo: "whatever",
         bar: "something else",
*         crudMode: "new",
         crudName: "myShinyObject"*
         ...
   }

Even more ideally, I could prepent underscores or something to the names so
they would obviously be out-of-band parameters. But that's a secondary
issue.

I don't really care how the params get there. Probably the best, easiest and
clearest way would be to somehow convert the form model (values) into a
key-value pair array (map? in JS parlance??), add the extra parameters to
that, and then submit it to the RPC object for submission. But I can't
figure out how to convert the model into an array either.

There doesn't appear to be any clear path from here to where I want to go.
The manual doesn't seem to help, nor any of the comments I've been able to
find on the net or Stack Overflow.


Thanks for helping me with this, I appreciate it!

john





--
View this message in context: http://qooxdoo.678.n2.nabble.com/Need-help-with-Models-please-tp7581630p7581642.html
Sent from the qooxdoo mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel


------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: Need help with Models please !!!!

jwhitten
Yes, I did look at your suggested solution. Thanks very much for suggesting it! Unfortunately, it is very similar to some of the umpteen ways I've already tried. Just to be absolutely certain however, I just went back and did it up and this is what I got.

Your suggested changes:

                _handleSubmit : function(e)
                {
                        var item = e.getData();
                        qx.core.Init.getApplication().debug("Model: " + item.getModel());
                        qx.core.Init.getApplication().getMainWindow().logEntry(item.getModel());
                        var service = this._getService(item);
                        var model = item.getModel();
                        model["crudMode"] = "new";
                        model["crudName"] = "myName";

                        this._callRpcSync(service, this.getUrl(), model);
                }

The results:




None of the "doctored" parameters make it across.

I had tried just creating new properties-- e.g., model.crudMode = this.getCrudMode(), which ends up looking about the same as yours in the debugger.

I've also tried making an array starting with my parameters and adding the form.model params to it. No good. I've tried making a model using qx.data.marshall.Json.createModel() and various attempts to merge the two together. It looks great in the debugger, but no go. They don't make it to the other end.

On the off chance that I'm doing something weird in my RPC code, here is the verbatim code lifted straight from my program:


                _callRpcSync : function(service, url, params) // synchronous model
                {
                        var rpc = new qx.io.remote.Rpc(url, service);

                        try {
                                var results = rpc.callSync(service, qx.util.Serializer.toUriParameter(params));
                                qx.core.Init.getApplication().getMainWindow().logEntry(results);
                                return results;
                                }
                        catch (exc) {
                                qx.core.Init.getApplication().debug("Exception occured during RPC-SYNC call: " + exc);
                                }
                },


Reply | Threaded
Open this post in threaded view
|

Re: Need help with Models please !!!!

Jim Hunter
What you need to do is to determine what format/structure 'item' is and add the data to it. I see that you have a debug message of the info, what does that message look like?

Jim


On Wed, Oct 10, 2012 at 10:51 AM, jwhitten <[hidden email]> wrote:
Yes, I did look at your suggested solution. Thanks very much for suggesting
it! Unfortunately, it is very similar to some of the umpteen ways I've
already tried. Just to be absolutely certain however, I just went back and
did it up and this is what I got.

Your suggested changes:

                _handleSubmit : function(e)
                {
                        var item = e.getData();
                        qx.core.Init.getApplication().debug("Model: " +
item.getModel());

qx.core.Init.getApplication().getMainWindow().logEntry(item.getModel());
                        var service = this._getService(item);
                        var model = item.getModel();
*                        model["crudMode"] = "new";
                        model["crudName"] = "myName";*
                        this._callRpcSync(service, this.getUrl(), *model*);
                }

The results:

<http://qooxdoo.678.n2.nabble.com/file/n7581644/10-10-2012_1-35-32_PM.png>


None of the "doctored" parameters make it across.

I had tried just creating new properties-- e.g., model.crudMode =
this.getCrudMode(), which ends up looking about the same as yours in the
debugger.

I've also tried making an array starting with my parameters and adding the
form.model params to it. No good. I've tried making a model using
qx.data.marshall.Json.createModel() and various attempts to merge the two
together. It looks great in the debugger, but no go. They don't make it to
the other end.

On the off chance that I'm doing something weird in my RPC code, here is the
verbatim code lifted straight from my program:


                _callRpcSync : function(service, url, params) // synchronous
model
                {
                        var rpc = new qx.io.remote.Rpc(url, service);

                        try {
                                var results = rpc.callSync(service,
*qx.util.Serializer.toUriParameter(params)*);

qx.core.Init.getApplication().getMainWindow().logEntry(results);
                                return results;
                                }
                        catch (exc) {

qx.core.Init.getApplication().debug("Exception occured during RPC-SYNC call:
" + exc);
                                }
                },






--
View this message in context: http://qooxdoo.678.n2.nabble.com/Need-help-with-Models-please-tp7581630p7581644.html
Sent from the qooxdoo mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel


------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: Need help with Models please !!!!

jwhitten

Here is the entire request payload:

{"service":"new","method":"new","id":1,"params":["id=__NEWID__&name=testname&network_id=qx.data.model.id%22name%5B3801-0%5D&quantity=6"]}

Reply | Threaded
Open this post in threaded view
|

Re: Need help with Models please !!!!

jwhitten
In reply to this post by Jim Hunter

This is what it looks like just before I call RPC Sync...

Reply | Threaded
Open this post in threaded view
|

Re: Need help with Models please !!!!

jwhitten
In reply to this post by Jim Hunter
This is what I did that actually got me the closest to what I saw in the debugger (and several variations on this theme). But none of them actually succeeded in getting ALL of the parameters to the other side. If I merge the model with the arry, I get the arry parameters. If I merge the arry with the model, I get the model parameters. But never both:


                _handleSubmit : function(e)
                {
                        var item = e.getData();
                        qx.core.Init.getApplication().debug("Model: " + item.getModel());
                        qx.core.Init.getApplication().getMainWindow().logEntry(item.getModel());
                        var service = this._getService(item);
                        var model = item.getModel();
                        var arry = qx.data.marshal.Json.createModel({
                                crudMode: "new",
                                crudName: "myName"
                                });
                        qx.lang.Object.mergeWith(model, arry, false);

                        this._callRpcSync(service, this.getUrl(), model);
                }


Here is an example of what it looks like in the debugger:



As you can see, it LOOKS good...

But when I continue the operation...



Once again, it doesn't make it to the back-end.
Reply | Threaded
Open this post in threaded view
|

Re: Need help with Models please !!!!

Jim Hunter
You didn't send the information I requested. I requested the output from your debug statement that happens BEFORE a call is made to the server and BEFORE you add any extra data to it. It looks like this can be solved if you please post the information I requested, nothing more.

Thanks,
Jim

On Wed, Oct 10, 2012 at 11:34 AM, jwhitten <[hidden email]> wrote:
This is what I did that actually got me the closest to what I saw in the
debugger (and several variations on this theme). But none of them actually
succeeded in getting ALL of the parameters to the other side. If I merge the
model with the arry, I get the arry parameters. If I merge the arry with the
model, I get the model parameters. But never both:


                _handleSubmit : function(e)
                {
                        var item = e.getData();
                        qx.core.Init.getApplication().debug("Model: " +
item.getModel());

qx.core.Init.getApplication().getMainWindow().logEntry(item.getModel());
                        var service = this._getService(item);
                        var model = item.getModel();
                        *var arry = qx.data.marshal.Json.createModel({
                                crudMode: "new",
                                crudName: "myName"
                                });
                        qx.lang.Object.mergeWith(model, arry, false);*
                        this._callRpcSync(service, this.getUrl(), model);
                }


Here is an example of what it looks like in the debugger:

<http://qooxdoo.678.n2.nabble.com/file/n7581648/10-10-2012_2-29-30_PM.png>

As you can see, it LOOKS good...

But when I continue the operation...

<http://qooxdoo.678.n2.nabble.com/file/n7581648/10-10-2012_2-31-46_PM.png>

Once again, it doesn't make it to the back-end.




--
View this message in context: http://qooxdoo.678.n2.nabble.com/Need-help-with-Models-please-tp7581630p7581648.html
Sent from the qooxdoo mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel


------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: Need help with Models please !!!!

jwhitten
Sorry about that, I reckon I misread your post.

Here is what it looks like before it gets tinkered with...

Reply | Threaded
Open this post in threaded view
|

Re: Need help with Models please !!!!

Jim Hunter
That's 'better', but it has the new data in it already and it's not the output from your debug statement like I asked. Do you know where that information is going? You have to look in theFireBug console or your browser Console if not using FireBird (which is my guess by your screenshot), and show me what is printed there from the debug statement. It appears that 'item' is a basic JSON object and adding the new properties, as was in my original post, will add the new data in at the same level as the field values. You need to simplify your code as much as possible, you are adding too many layers of confusion onto it. There is no need to call any methods to add a property to a JSON, simply add it (someJSON.newItem = "new value"). It really is that simple.

Jim


On Wed, Oct 10, 2012 at 2:05 PM, jwhitten <[hidden email]> wrote:
Sorry about that, I reckon I misread your post.

Here is what it looks like before it gets tinkered with...

<http://qooxdoo.678.n2.nabble.com/file/n7581650/10-10-2012_4-59-49_PM.png>



--
View this message in context: http://qooxdoo.678.n2.nabble.com/Need-help-with-Models-please-tp7581630p7581650.html
Sent from the qooxdoo mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel


------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: Need help with Models please !!!!

jwhitten
Sorry about that-- I'm guess I'm having a long day :-)

Here is the correct view.  And I'll re-post the entire code as well.



This is the Generic Class:

qx.Class.define("reilly.ui.form.Generic",
{
        extend : qx.ui.form.Form,

        properties :
        {
                url: { init: null }, // back-end service url
                crudMode: { init: null },
                crudName: { init: null },
                controller : { deferredInit : true },
                model : { deferredInit : true },
                service : { init: "read" } // service name for backend
        },

        events :
        {
                "onSubmit" : "qx.event.type.Data", // called when Save / Submit button pressed
                "onCancel" : "qx.event.type.Data", // called when Cancel button pressed
                "onFinish" : "qx.event.type.Data" // called when form action is complete
        },

        construct : function()
        {
                this.base(arguments);
        },

        members :
        {
                _getSelectBox : function(display_field, data)
                {
                        // set up device type combo box
                        var selectbox = new qx.ui.form.SelectBox().set({required: true});

                        if (display_field) { // multi-dimensional data
                                // new qx.data.controller.List(new qx.data.Array(data), selectbox); // bind list model to selectbox-list
                                var selectboxModel = qx.data.marshal.Json.createModel(data);
                                new qx.data.controller.List(selectboxModel, selectbox, display_field); // bind list model to selectbox-list
                                }
                        else {
                                new qx.data.controller.List(new qx.data.Array(data), selectbox); // bind list model to selectbox-list
                                // var selectboxModel = qx.data.marshal.Json.createModel(data);
                                // new qx.data.controller.List(selectboxModel, selectbox); // bind list model to selectbox-list
                                }



                        return selectbox;
                },

                _getButton : function(caption, fire_event_name, listen_event_name)
                {
                        var button = new qx.ui.form.Button(caption);
                        if (!listen_event_name) { listen_event_name = "execute"; } // default listener event name
                        button.addListener(listen_event_name, function(e) {
                                this.fireDataEvent(fire_event_name, this);
                                }, this);
                        return button;
                },

                //---------------------------------------------------------------------
                // Manage RPC Calls
                //---------------------------------------------------------------------

                //----------------------------------------------------------------------
                _getService : function(item)
                {
                        try { // try to get the service name
                                var service = item.getService();
                                qx.core.Init.getApplication().debug("RPC Service will be: " + service);
                                return service;
                                }
                        catch (exc) { // don't care what the error is, just don't bomb
                                qx.core.Init.getApplication().debug("Item has no service property: " + exc);
                                }
                        return "echo";
                },

                //----------------------------------------------------------------------
                _callRpcSync : function(service, url, params) // synchronous model
                {
                        var rpc = new qx.io.remote.Rpc(url, service);

                        try {
                                var results = rpc.callSync(service, qx.util.Serializer.toUriParameter(params));
                                qx.core.Init.getApplication().getMainWindow().logEntry(results);
                                return results;
                                }
                        catch (exc) {
                                qx.core.Init.getApplication().debug("Exception occured during RPC-SYNC call: " + exc);
                                }
                },

                //----------------------------------------------------------------------
                _handleSubmit : function(e)
                {
                        var item = e.getData();
                        qx.core.Init.getApplication().debug("Model: " + item.getModel());
                        qx.core.Init.getApplication().getMainWindow().logEntry(item.getModel());
                        var service = this._getService(item);
                        var model = item.getModel();
                        var arry = qx.data.marshal.Json.createModel({
                                crudMode: this.getCrudMode(),
                                crudName: this.getCrudName()
                                });
                        qx.lang.Object.mergeWith(model, arry, false);
                        this._callRpcSync(service, this.getUrl(), model);
                }
        }
});



And here is the class that is being subclassed from it:



qx.Class.define("reilly.ui.form.Test",
{
        extend : reilly.ui.form.Generic,

        properties :
        {
        },

        events :
        {
        },

        construct : function()
        {
                this.base(arguments);
                this.setService('new');
                this.setUrl("MY URL GOES HERE");
                this.setCrudMode("new");
                this.setCrudName("test");

                // set up model for form
                var myData = {
                        id : "__NEWID__", // serial
                        name : "testname", // varchar
                        network_id : null, // integer
                        quantity : "6" // integer
                        };
                var formModel = qx.data.marshal.Json.createModel( myData );

                this.add(new qx.ui.form.TextField().set({readOnly: true}), "Id", null, "id");
                this.add(new qx.ui.form.TextField().set({required: true}), "Name", null, "name");

                var network_id = this._getSelectBox("name", ([
                        { id: 68, name: "SPCL_TEST_500 - For Testing Purposes Only" },
                          ...
                        ]));
                this.add(network_id, "Network", null, "network_id");

                this.add(new qx.ui.form.TextField().set({required: true}), "Quantity", null, "quantity");

                // save button
                this.addButton(this._getButton("Cancel", "onCancel"));
                this.addButton(this._getButton("Save", "onSubmit"));

                // create form controller & model
                var formCtlr = new qx.data.controller.Form(formModel, this);
                this.initController(formCtlr);
                this.initModel(formModel);

/*
                // alter binding for 'device' control
                formCtlr.addBindingOptions(network_id, {
                        converter: function(data) {
                                var model = network_id.getModel();
                                for (var i = 0; i < model.getLength(); i++) {
                                        if (model.getItem(i).getId() == data) {
                                                return model.getItem(i);
                                                }
                                        }
                                }
                        },
                        {
                        converter: function(data) {
                                return data.getId();
                                }
                        });

*/
        },

        members :
        {
        }
});
Reply | Threaded
Open this post in threaded view
|

Re: Need help with Models please !!!!

jwhitten
In reply to this post by Jim Hunter


>> There is no need to call any methods to add a property to a JSON, simply add it (someJSON.newItem = "new value"). It really is that simple


I agree, and that was the VERY FIRST thing I tried, honest!  :-) And I was really surprised when it didn't work.
Reply | Threaded
Open this post in threaded view
|

The SOLUTION!!! (Was Re: Need help with Models please !!!!)

jwhitten
TA DAH!!! Here is the WORKING solution !!! 


                _callRpcSync : function(service, url, params) // synchronous model
                {
                        var rpc = new qx.io.remote.Rpc(url, service);

                        try {
                                return rpc.callSync(service, qx.util.Serializer.toUriParameter(params));
                                }
                        catch (exc) {
                                qx.core.Init.getApplication().debug("Exception occured during RPC-SYNC call: " + exc);
                                }
                },

                //----------------------------------------------------------------------
                _objToArray : function(obj)
                {
                        var arry = {};
                        var properties = qx.util.PropertyUtil.getAllProperties(obj.constructor);
                        for (var name in properties) {
                                if (properties[name].group != undefined) {
                                        continue;
                                        }
                                var value = obj["get" + qx.lang.String.firstUp(name)]();
                                arry[name] = value;
                                }
                        return arry;
                },


                //----------------------------------------------------------------------
                _handleSubmit : function(e)
                {
                        var item = e.getData();
                        var service = this._getService(item);
                        var model = item.getModel();
                        var arry = this._objToArray(model);
                        arry.crudMode = this.getCrudMode();
                        arry.crudName = this.getCrudName();
                        var new_model = qx.data.marshal.Json.createModel( arry, true );

                        this._callRpcSync(service, this.getUrl(), new_model);
                }


Here is the final result !!




To be sure, this is somewhat of a hack, but it was definitely not just dealing with some "simple JSON". The code that does the Uri construction is calling the constructor of the object which is returning the original items over and over, irrespective of any NEW "properties" which may have been added subsequently. Similarly, attempting to merge two objects using qx.lang.Object.mergeWith() didn't quite work either for the same reason-- the Serializer code was calling the constructor. So whichever object was set to be the "target" object, that's the object whose constructor was called and thus which "properties" were included. The only way (I have been able to figure out) to do it is to create a plain array, iterate the form model's properties-- so as to create a plain JSON object-- and then to add the new properties-- the "crud" values-- into that and then hoist it into a new model object with qx.data.marshal.Json.createModel( json_data ). Then when that is submitted to the Serializer, its constructor contains all of the needed properties.


From: Qooxdoo's Serializer.js:


    toUriParameter : function(object, qxSerializer, dateFormat)
    {
      var result = "";
      var properties = qx.util.PropertyUtil.getAllProperties(object.constructor);

      for (var name in properties) {
        // ignore property groups
        if (properties[name].group != undefined) {
          continue;
        }
        var value = object["get" + qx.lang.String.firstUp(name)]();


        // handle arrays
        if (qx.lang.Type.isArray(value)) {
          var isdataArray = qx.data && qx.data.IListData &&
            qx.Class.hasInterface(value && value.constructor, qx.data.IListData);
          for (var i = 0; i < value.length; i++) {
            var valueAtI = isdataArray ? value.getItem(i) : value[i];
            result += this.__toUriParameter(name, valueAtI, qxSerializer);
          };
        } else if (qx.lang.Type.isDate(value) && dateFormat != null) {
          result += this.__toUriParameter(
            name, dateFormat.format(value), qxSerializer
          );
        } else {
          result += this.__toUriParameter(name, value, qxSerializer);
        }
      }
      return result.substring(0, result.length - 1);
    },

Reply | Threaded
Open this post in threaded view
|

Re: The SOLUTION!!! (Was Re: Need help with Models please !!!!)

jwhitten


BTW Jim, thank you very much for your assistance and patience!

I appreciate it.

John
Reply | Threaded
Open this post in threaded view
|

Re: The SOLUTION!!! (Was Re: Need help with Models please !!!!)

Jim Hunter
Glad you got it working. I still think there are too many moving parts. I send form data to a server on a daily basis and never have I ever used createModel(). Did you write the server code or were you stuck with the API? Usually sending a standard JSON object as a POST param is more then sufficient to get the info to the server. It might also be because I don't call RPC's I just send the data to a basic server method that parses the data. Pretty straight forward.

Good to know you got it going.

Jim


On Wed, Oct 10, 2012 at 7:09 PM, jwhitten <[hidden email]> wrote:


BTW Jim, thank you very much for your assistance and patience!

I appreciate it.

John



--
View this message in context: http://qooxdoo.678.n2.nabble.com/Need-help-with-Models-please-tp7581630p7581657.html
Sent from the qooxdoo mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel


------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
12