Originally posted by kccheng
Announcement
Collapse
No announcement yet.
X
-
-
Help
I'm trying to deploy a rest php with an hardcoded response, but the grid stucks on "Loading data..."
Here is the php code:
Code:<?php $json = array(); $json['response'] = array(); $json['response']['status'] = 0; $json['response']['startRow'] = 0; $json['response']['endRow'] = 1; $json['response']['totalRows'] = 2; $json['response']['data'] = array(); $json['response']['data'][0] = array(); $json['response']['data'][0]['ipAddress'] = "128.0.0.1"; $json['response']['data'][0]['hostName'] = "host1"; $json['response']['data'][1] = array(); $json['response']['data'][1]['ipAddress'] = "128.0.0.2"; $json['response']['data'][1]['hostName'] = "host2"; echo json_encode($json); ?>
Code:import com.smartgwt.client.data.RestDataSource; import com.smartgwt.client.types.DSDataFormat; import com.smartgwt.client.data.fields.*; public class SimpleRestDataSource extends RestDataSource { public SimpleRestDataSource() { int minWidth = 100; DataSourceTextField ipAddressField = new DataSourceTextField( "ipAddress", "Ip Address", minWidth); ipAddressField.setRequired(true); ipAddressField.setPrimaryKey(true); DataSourceTextField hostNameField = new DataSourceTextField("hostName", "Host Name", minWidth); setFields(ipAddressField, hostNameField); setDataFormat(DSDataFormat.JSON); setFetchDataURL("php/assetDS.php"); setAddDataURL("php/assetDS.php"); setUpdateDataURL("php/assetDS.php"); setRemoveDataURL("php/assetDS.php"); setClientOnly(false); } }
Code:ListGrid grid = new ListGrid(); grid.setDataSource(new SimpleRestDataSource()); grid.setAutoFetchData(true); panel.addMember(grid);
Thank you, caru.
Comment
-
It should work. The only difference between your code and mine is, that you setCode:grid.setAutoFetchData(true);
Code:grid.fetchData();
Maybe you try to your code with the google web toolkit development shell. If you do so be aware, that you have to configure the included webserver to execute the requested php-script and not just display the code. You can solve this problem easily by compiling your code and try your application on your own webserver which should be able to execute php-scripts.
Comment
-
I found the problem... it was the "real server" :-/ I'm very sorry for having taken your time, but when I tried it with another server of another hosting company, everything went well... anyway, thank you for your interest!
What can be wrong with the first server? Please note that if I try to access the .php directly I correctly get the json printed out on the page...
Resolved: the first server is a cheap hosting one, and attacches a google analytics script at the end of each page, including to the JSON returned by the php. So, nothing to do with SmartGwt, which behaves appropriately.Last edited by caru; 25 Mar 2009, 19:30.
Comment
-
On the public wiki there is now a series of articles showing how to build PHP server code for RestDataSource that supports full CRUD, including AdvancedCriteria and transactional commits to a database (using the RedBean PHP library). Take a look here.
This code is also generic across different DataSources - similar to how our Java server uses an XML definition of the DataSource, this PHP code parses JSON DataSource definitions (isc.RestDataSource.create({..})) so you only define your DataSource in one place and both client and server behaviors result from it.Last edited by Isomorphic; 8 May 2013, 12:48.
Comment
Comment