PDA

View Full Version : [Solved] JSONRPC 2.0 and jsonStore



bass-x
7 Apr 2010, 3:31 AM
I've programmed a XML-RPC server for some client tools on local machines. The XML-RPC server calls the right PHP script on the server (methods) for the user and give the client a XMl-RPC response back. Now we want to build some tools in ExtJS to become platform independed. Well we first programmed a XML-RPC client between the jsonstore and the XML-RPC server (for beta version). Now we programmed a JSON-RPC server next to the XML-RPC server. Depending on the content type of the requested page the right server will be used. and will also output the content in the right format. The problem between JSON-RPC and the jsonStore is that the difference in format. We output something like this from the server:

{"jsonrpc": "2.0", "result": {"propertylist1":["item 1","item 2","item 3","item 4"],"propertylist 2":["item 1","item 2","item 3","item 4","item 5"],"propertylist 3":["item 1","item 2","item 3","item 4","item 5","item 6","item 7"],"propertylist 4":["item 1","item 2","item 3"],"propertylist 5":["item 1","item 2"]}, "id": 4}

This result in XML-RPC format will be used in other software to load a group of 5 popup buttons (combo boxes). Without changing the methods nor deviating from the jsonrpc 2.0 standard I want to know how I can load this data also in the right combo boxes in ExtJS. I tried with a jsonStore to set the root to 'result.propertylist1' but that won't work either. I see 4 empty items in the list but has no value . I'm not sure if jsonstore is the right solution so I was wondering what you guys think it's the best thing to do here.

Note: the methods on the server can't be changed because already hundreds of methods is in use with other client software.




Smilies :):D;)/:) :))=P~:">B) :>\:D/8-|=D> :-?:-|~o):( (:|:((I-|=; :s>:):-/

bass-x
7 Apr 2010, 7:08 AM
I've got the problem solved.

I use one json store and the stores to the combo boxes are empty arrays. Then I added a handler when the store is loaded. Then I'll populate the combo boxes with arrays with loadData().

Something like this works now


var mainStore = new Ext.data.JsonStore({
autoDestroy: true,
url: '<?php echo $_SERVER['PHP_SELF'];?>?action=method.name',
storeId: 'mainStore',
root: 'result', //is the root from JSONRPC
idProperty: 'propertylist1', //can be any field, we don't use this
fields: ['propertylist1', 'propertylist2', 'propertylist3', 'propertylist4', 'propertylist5']
});

mainStore.on('load', function(theStore, records, options){
cmb1.store.loadData(records[0].get('propertylist1'));
cmb2.store.loadData(records[0].get('propertylist2'));
cmb3.store.loadData(records[0].get('propertylist3'));
cmb4.store.loadData(records[0].get('propertylist4'));
cmb5.store.loadData(records[0].get('propertylist5'));
})


var cmb1 = new Ext.form.ComboBox({
lazyRender:false,
allowBlank: false,
mode: 'local',
editable: false,
emptyText: 'Select value',
forceSelection: true,
store: [],
triggerAction: 'all',
});

...same for all those other comboboxes

at last ...

mainStore.load();