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


  • implement the simple front-end jMaki application (as described here)

  • change the table widget to editable dojo table (replace name="yahoo.dataTable" with name="dojo.etable" in the index.jsp page. it is really simple, isn't it?)

  • and add the above mentioned snippet into your glue.js

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 ;-)

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Jakub Podlesak

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today