-
13 Jan 2009 1:23 AM #1
extjs and Json
extjs and Json
hi,
I am looking for your help
I face a problem in joining the EXTJS and java with JSON
note down that i am employing the servlet
I would appreciate a prompt response from you
-
13 Jan 2009 4:14 AM #2MJ
API Search || Ext 3: docs-demo-upgrade guide || User Extension Repository
Frequently Asked Questions: FAQs
Tutorial: Grid (php/mysql/json) , Application Design and Structure || Extensions: MetaGrid, MessageWindow
-
13 Jan 2009 4:27 AM #3
Server to Client
var elemt = Ext.util.JSON.encode('your Object')
Cient to Server
JSONObject jsonObject = new JSONObject('elemt')
-
13 Jan 2009 4:28 AM #4
1. Make an object like blablaData
2. send it to the servlet like this: .....blabla:Ext.util.JSON.encode(blablaData)...
3. in the servlet: JSONObject materialObject = new JSONObject(request.getParameter("blabla"));
-
14 Jan 2009 12:40 AM #5
Thanks for your answer, but I want to send data from the servlet to a js page for reason to display it in a grid panel.
this is my source code:
file MyServlet.java:
in the browser I have this result:Code:import javax.servlet.http.HttpServlet; import java.io.*; import java.sql.*; //import java.text.*; //import java.util.*; import javax.servlet.*; import javax.servlet.http.*; import net.sf.json.*; @SuppressWarnings("serial") public class ClieentServlet extends HttpServlet { ........................ public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { //Create a JSONObject: JSONObject myObject = new JSONObject(); //Put data in this Object myObject.put("firstname","Jeans"); myObject.put("lastname","Louis"); myObject.put("job","developper"); out.println(myObject); } }
Now I would recover this data and put it in a gridPanel using Extjs, I have write this js code:Code:{"firstname":"Jeans","lastname":"Louis","job":"developper"}
But in the results of this, I obtain an empty grid??Code:Ext.onReady(function(){ var store = new Ext.data.Store({ reader : reader, autoLoad : true, remoteSort : true, proxy : new Ext.data.HttpProxy({ url : 'http://localhost:8081/jsonJSPExtjs/clientinfo', }) }); var emp = Ext.data.Record.create([ { name: 'firstname'}, { name: 'lastname'}, { name: 'job'} ]); var reader = new Ext.data.JsonReader({ root : "myObject", }, emp); var grid1 = new Ext.grid.GridPanel({ store: store, cm: new Ext.grid.ColumnModel([ {header : "Name", width: 8, dataIndex : 'firstname'}, {header: "LastName, width: 10, dataIndex: 'lastname'}, {header: "Job", width: 10, dataIndex: 'job'} ]), viewConfig: { forceFit:true }, width: 600, height: 300, collapsible: true, animCollapse: false, title: 'EmployeeInformation', iconCls: 'icon-grid', renderTo: document.body }); store.load(); });
Thanks for help
-
14 Jan 2009 1:35 AM #6
-
14 Jan 2009 2:11 AM #7Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 41
Actually, to match your reader you would need:
But I would use:Code:JSONObject myRecord = new JSONObject(); myRecord.put("firstname","Jeans"); myRecord.put("lastname","Louis"); myRecord.put("job","developper"); JSONArray myRecords = new JSONArray(); myRecords.put(myRecord); JSONObject myObject = new JSONObject(); myObject.put("myObject",myRecords); out.println(myObject);
and remove the root from the JsonReader.Code:JSONObject myRecord = new JSONObject(); myRecord.put("firstname","Jeans"); myRecord.put("lastname","Louis"); myRecord.put("job","developper"); JSONArray myRecords = new JSONArray(); myRecords.put(myRecord); out.println(myRecords);
-
14 Jan 2009 2:19 AM #8
-
14 Jan 2009 2:59 AM #9
-
14 Jan 2009 5:04 AM #10Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 41
1. Define your reader and record before you create the store.
2. You use autoLoad:true AND load() the store (one is enough).
3. You use url:'http://localhost:8081/jsonJSPExtjs/clientinfo'. Is your HTML also located on http://localhost:8081 (XSS restriction) ?
4. If you still can't get it to load, try if the loadexception event is fired on the store.


Reply With Quote