Japod's blog
Archives
« May 2008
SunMonTueWedThuFriSat
    
1
2
3
4
5
6
7
8
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
       
Today
Click me to subscribe
Search

Links
 

View My Stats
« Previous day (May 8, 2008) | Main | Next day (May 10, 2008) »
Friday May 09, 2008
jMaki Putting Data to Jersey

In this post I have described how to make jMaki widgets consume Jersey based web resources. In a read-only manner.

Here I would like to show how to close the circle and make jMaki widgets push an updated information back to the Jersey. Many thanks to Greg Murray who has spent some time with me on Monday to put the following piece of code together.

The most important part of it is emphasized and shows how to actually make a PUT request
using jMaki function doAjax


jmaki.subscribe("/dojo/etable/onCellEdit", function(arg) {
jmaki.doAjax({
url: "/jMakiBackend/webresources/printers/ids/"+arg.row,
headers:[{name:"Accept", value:"application/json"}],
callback:function(ar){
var i = eval("("+ar.responseText+")");
var cols = ["id", "model", "url", "location"]
eval("i." + cols[arg.column]+"='"+arg.value+"'");
jmaki.doAjax({
url: "jMakiBackend/webresources/printers/ids/"+arg.row,
headers:[{name:"Content-type", value:"application/json"}],
method:"PUT",
body : jmaki.json.serialize(i)
})

}
})
})

All you need to make it work is to

Then you should be able to update an information in the table widget and see it updated also in the underlaying web resource representation. I have not tried, but suppose that updating printer ids shouldn't work ;-)