PDA

View Full Version : Does ScriptTagProxy work with XmlReader?



dkann
11 Aug 2009, 11:26 AM
Hi,

I am trying to use ScriptTagProxy to set the store of a combo box in my application, as shown below. I have created a small app to test this issue. I have run this app ,using HttpProxy and ScriptTagProxy, alternatively, but only HttpProxy works (although it does show the warning window, since I am accessing a different domain, as expected). I want to make it work using the ScriptTagProxy and XMLReader. I am using GXT 1.2.4. Can anyone help?



private ComboBox addComboBox(){
ComboBox cb = new ComboBox();

String url = "http://localhost:81/tmws/XYZService.asmx/...";
ModelType type = new ModelType();
type.root = "root";
type.recordName = "record";
type.addField("ID");
type.addField("Name");

XmlReader<ModelData> reader = new XmlReader<ModelData>(type);

// final HttpProxy<Object, BaseListLoadResult<ModelData>> proxy =
// new HttpProxy<Object, BaseListLoadResult<ModelData>>(
// new RequestBuilder(RequestBuilder.GET, url));

final ScriptTagProxy<ModelData, BaseListLoadResult<ModelData>> proxy =
new ScriptTagProxy<ModelData, BaseListLoadResult<ModelData>>(url);


final BaseListLoader loader = new BaseListLoader(proxy, reader);

ListStore<ModelData> store = new ListStore<ModelData>(loader);

cb.setStore(store);
cb.setDisplayField("Name");

loader.load();

return cb;
}

Arno.Nyhm
13 Aug 2009, 12:53 AM
you know that you need to give back a special callback code if you use scripttagproxy?
see here: http://extjs.com/deploy/ext/docs/output/Ext.data.ScriptTagProxy.html (http://extjs.com/forum/../deploy/ext/docs/output/Ext.data.ScriptTagProxy.html)

dkann
13 Aug 2009, 10:21 AM
Hi,

I don't understand what you mean by giving special callback code. I followed the example for advanced combo box from Ext 1.2.4 Explorer (http://extjs.com/explorer/#advancedcombobox) and tried to write my code. In that example the ScriptTagProxy uses JsonReader. I am trying to use XmlReader.

Here is the code from my second attempt at getting this working.



private ComboBox<ModelData> cb = new ComboBox<ModelData>();

String url = "http://localhost:81/tmws/XYZService.asmx/...";

ScriptTagProxy<Object, BaseListLoadResult<ModelData>> proxy =
new ScriptTagProxy<Object, BaseListLoadResult<ModelData>>(url){
@Override
public void load(
DataReader<Object, BaseListLoadResult<ModelData>> reader,
Object loadConfig,
AsyncCallback<BaseListLoadResult<ModelData>> callback) {
GWT.log("Loading", null);
super.load(reader, loadConfig, callback);
}

@Override
protected void onReceivedData(String transId,
JavaScriptObject jso) {
GWT.log("On received Data", null);
super.onReceivedData(transId, jso);
}

};

ModelType type = new ModelType();
type.root = "Root";
type.recordName = "Record";
type.addField("ID");
type.addField("Name");

XmlReader<ListLoadConfig> reader = new XmlReader<ListLoadConfig>(type){
@Override
protected ListLoadResult newLoadResult(ListLoadConfig loadConfig,
List<ModelData> models) {
BaseListLoadResult result = new BaseListLoadResult(models);
GWT.log("returning results", null);
return result;
}
};

final BaseListLoader loader = new BaseListLoader(proxy, reader);

ListStore<ModelData> store = new ListStore<ModelData>(loader);

cb.setStore(store);
cb.setDisplayField("Name");
loader.load();
In my testing I noticed that the 'load' method of scripttagproxy is called and the combobox shows the 'Loading..' message. The onReceivedData() and XmlReader.newLoadResult() are never called.

Has anyone tried to use Xmlreader with ScriptTagProxy successfully? Any help is greatly appreciated.

Thanks in Advance.
DKann

Arno.Nyhm
13 Aug 2009, 11:29 AM
Hi,I don't understand what you mean by giving special callback code.

did you realy read this link?
http://extjs.com/deploy/ext/docs/output/Ext.data.ScriptTagProxy.html (http://extjs.com/forum/../deploy/ext/docs/output/Ext.data.ScriptTagProxy.html)




I followed the example for advanced combo box from Ext 1.2.4 Explorer (http://extjs.com/explorer/#advancedcombobox) and tried to write my code. In that example the ScriptTagProxy uses JsonReader. I am trying to use XmlReader.

XMLReader reads XML
ScriptTagProxy reads a JavaScript Callback with JsonData.

so your servercode need to return the well formed data!



can you post some code how you give the data back in:
http://localhost:81/tmws/XYZService.asmx/...

Arno.Nyhm
13 Aug 2009, 11:43 AM
you can look into the results if you look at this links (generated from your example):

With ScriptTagProxy:

http://extjs.com/forum/topics-remote.php?callback=transId2&sortField=null&sortDir=NONE&start=0&limit=10&query=test
http://extjs.com/forum/topics-remote.php?callback=transId2&sortField=null&sortDir=NONE&start=0&limit=10&query=test


With normal Call:

http://extjs.com/forum/topics-remote.php?sortField=null&sortDir=NONE&start=0&limit=10&query=test
http://extjs.com/forum/topics-remote.php?sortField=null&sortDir=NONE&start=0&limit=10&query=test

mdlincoln
13 Aug 2009, 1:16 PM
Take a look at this thread.

http://extjs.com/forum/showthread.php?p=256243#post256243

I ran into the same problem a while ago in ExtJS. Hopefully, my solution will work for your case.

Mark

Arno.Nyhm
14 Aug 2009, 7:52 AM
thx :-)

one other solution is to write a "proxy" on the server which just forward the request to the remote server and then flush the responded data 1:1 to the client.
in this case the xml response comes from the same domain and you can avoid the security message.

sbrau
30 Sep 2009, 8:37 AM
Did someone find a final solution? I got the same pb and I just began to search a new Proxy implementation

thx

Arno.Nyhm
1 Oct 2009, 12:53 AM
pls describe your requirements and what you have tested right now. and some example code snippets.

sbrau
1 Oct 2009, 1:26 AM
Right now, I didn't find a solution.
My goal is to download a xml file (RSS) on an external server. I can't use an Async function to ask my server to do the job for me (own Framework restriction), that's why the client should be independent.
I did the same error with a ScriptTagProxy and a XmlReader (Like dkann post). I only find solution that return Json and no XML reader implementation. That's why I ask if someone has find a solution to change the Proxy to load a XML file.

Sylvain

Condor
1 Oct 2009, 2:46 AM
ScriptTagProxy needs a very specific response (javascript callback). It does actually support an XmlReader, as long as your javascript callback method passes an XML document.

But can your external server actually return XML wrapped in a javascript callback method? If not, then you can't use a ScriptTagProxy and you have to proxy the data using your own server.

marmara95
7 Oct 2009, 6:01 AM
hi;

ds = new Ext.data.GroupingStore({
proxy: new Ext.data.ScriptTagProxy({
url: 'http://json.1sunucu.com/Json.php'
}),
reader: new Ext.data.JsonReader({
id: 'Code',
totalProperty: 'total',
root: 'data'
}, Ext.data.Record.create([
{name:'Code'},
{name:'Name'},
{name:'Brand'},
{name:'Keywords'},
{name:'Supplier'},
{name:'Vat'},
{name:'Price_buy'},
{name:'Price_sell'},
{name:'Price_special'},
{name:'Currency'},
{name:'Stock'}
])),
sortInfo: {field: 'Name', direction: 'ASC'},
remoteSort: true
});

i use scriptTagProxy in this way. it works on firefox but there is a problem in ie. i couldn't return data. what can i do?

Condor
7 Oct 2009, 6:20 AM
What does http://json.1sunucu.com/Json.php return?

Is the Content-type set to text/javascript?
Is the JSON valid (run it through jslint.com)?

sbarakat
27 Oct 2009, 1:32 AM
Hello,
Can anyone please tell me how do you fill the response at the server side.
I am trying to fill it in a Json object(JSONObject) but i ve got a script error Expected ";".
Thank you for your answer.

Condor
27 Oct 2009, 3:46 AM
Which server platform (language etc.)? Post the code you are currently using.

sbarakat
4 Nov 2009, 7:14 AM
The problem had been fixed. I was missing to send the callBackID with the response. Now it is working successfully.
In all cases thank you for your support

Arindam Das
6 May 2010, 12:49 AM
Hi Please see my reply herehttp://www.extjs.com/forum/showthread.php?89343-ScriptTagProxy-and-XML-Why-doesn-t-Extjs-provide-an-implementation&p=464924#post464924