Hi!

  I'm following the same tutorial. I finally could make it fully work with WO (creating, updating, deleting, etc).

  I did the following changes:

  1) SC expects variables to be camel-cased and not underscored. The SproutCore format created on ERRest was set to underscore variables, so isDone was being converted to is_done, and it would not work (tasks fetched from the server would never be ticked).

  2) As you noticed, "records" should be "content". I submitted a patch to ERRest fixing this problem and the previous.

  3) All URLs have to be adapted, including Update and Delete URLs that have to be built like this:

SC.Request.putUrl('/WO/WebObjects/Todos.woa/-6666/ra/Task/' + store.idFor(storeKey) + '.sc').json()

  4) Apparently, who wrote the tutorial assumed the backends would return an object in response to the PUT request. ERRest will always return an array, so you have to get objectAt(0) on the client side. This is a little hard to fix in ERRest, however, I believe it's not broken at all. The thing is, there appears to be no well defined conventions or standards on this (which is always nice for a protocol...), which means it's really however the app developer wants it to be. So, if you're using ERRest, you want it to be an array. ;)

  I think those were all the issues. I attach my data source file so you can compare. If you adjust the URLs to match yours, it should be just a matter of dropping it in on your client and it should work.

  If you want, please feel free to update Wonder's wiki! ;)

  Yours

Miguel Arroz

Attachment: task.js
Description: JavaScript source


On 2010/05/26, at 20:30, Johnny Miller wrote:

OK, so here was the issue.

In the Todos tutorial Chapter 7 they have you add a method to handle the server response.

didFetchTasks: function(response, store, query) {
if(SC.ok(response)) {
store.loadRecords(Todos.Task, response.get('body').content);
store.dataSourceDidFetchQuery(query);
} else store.dataSourceDidErrorQuery(query, response);
},

If you are using ERRest's JSON formatter you don't need the .content .  I thought that was a call to a function but it turns out that is just an attribute that it anticipates. 

i.e. 

{ "content" : [{"type":"Task","description":"Build my first SproutCore app","guid":"task-1","isDone":false},{"type":"Task","description":"Build a really awesome SproutCore app","guid":"task-2","isDone":false},{"type":"Task","description":"Next, the world!","guid":"task-3","isDone":false},{"type":"Task","description":"Integrate with ERRest","guid":"task-4","isDone":false}]}

If you are using ERRest's SproutCore formatter in place of using .content you should use .records

i.e here is the .sc response:

{"records":[{"type":"Task","description":"Build my first SproutCore app","guid":"task-1","is_done":false},{"type":"Task","description":"Build a really awesome SproutCore app","guid":"task-2","is_done":false},{"type":"Task","description":"Next, the world!","guid":"task-3","is_done":false},{"type":"Task","description":"Integrate with ERRest","guid":"task-4","is_done":false}],"ids":[null,null,null,null],"count":4}

If you'd like me to fill out the tutorial just let me know,

Johnny





On May 25, 2010, at 3:20 PM, Pascal Robert wrote:

I don't have an answer for you, but if you get it working, please update this page :-)

http://wiki.objectstyle.org/confluence/display/WONDER/SpoutCore+and+ERRest

Hi,

I'm trying to work through the sample sproutcore application found here:  http://wiki.sproutcore.com/Todos%C2%A0Intro

In place of the backends they recommend I'm trying to hook it up to ERRest.  I've created the POJO for the object they want us to use and ERRest is vending the JSON.  I can see from the sc-server log that it successfully requests the data but it doesn't get loaded into the application.

Has anyone else worked through the example SproutCore app and if so can you give me a pointer?

Thanks in advance,

Johnny Miller
Kahalawai Media Corp
http://www.kahalawai.com



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/probert%40macti.ca

This email sent to [email protected]


Johnny Miller
Kahalawai Media Corp



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/arroz%40guiamac.com

This email sent to [email protected]


Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to