PDA

View Full Version : need help urgent



setu01
25 Mar 2011, 5:12 PM
hi guys

I am new to ExtJS, just started looking into simple example to make it work but I could not figure it out.
I have a servlet thats sending the json string back to my extjs, the grid panel is using the store and trying to layout the panel. I see the response in firebug, but my grid is always empty. please help.

++++++++++++++++++++
here is my jasongrid.js

/*!
* Ext JS Library 3.1.1
* Copyright(c) 2006-2010 Ext JS, LLC
* [email protected]
* http://www.extjs.com/license
*/
Ext.onReady(function() {

var store = new Ext.data.JsonStore({
root: 'names',
totalProperty: 'totalRows',
idProperty: 'threadid',
remoteSort: true,

fields: ['firstName','lastName','age'],

proxy: new Ext.data.HttpProxy({
//url:'http://localhost:8080/ExtjsPaging/Bug',
url:'http://localhost:8080/register/populate',
method:'GET'
})
});


alert("Ext JS is working!:"+store);
var grid = new Ext.grid.GridPanel( {
store : store,
columns : [ {
header : "Last Name",
width : 150,
dataIndex : 'lastName',
sortable : true
}, {
header : "Age",
width : 150,
dataIndex : 'age',
sortable : true
}, {
header : "First Name",
width : 100,
dataIndex : 'firstName',
sortable : true
} ],
renderTo : 'example-grid',
width : 402,
height : 200
});

store.load();
});

++++++++++++++++++++
here is grid.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="../../resources/css/ext-all.css" />
<script type="text/javascript" src="../../adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="../../ext-all.js"></script>
<link rel="stylesheet" type="text/css" href="../shared/examples.css" />
<title>Title</title>
<script type="text/javascript" src="jsongrid.js">
</script>
</head>
<body>
<div id="example-grid"></div>
</body>
</html>

+++++++++++++++++++++++++++++
here is my populate servert.


import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
* Servlet implementation class Populate
*/
public class Populate extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#HttpServlet()
*/
public Populate() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession();
System.out.println("Populate Called!!");
try {
String jsonData = "{totalRows:3,names:[{lastName:'Patil',age:23,firstName:'Rohan'},{lastName:'Kumar',age:23,firstName:'Arun'},{lastName:'Patilaaa',age:23,firstName:'Basava'}]};";
PrintWriter out = response.getWriter();
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
out.println(jsonData);
out.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}

}

can someone please help me with whats wrong here? why do I not get data in grid?

-Setu

conorarmstrong
26 Mar 2011, 1:46 PM
not familiar with servlets as a backend but does the fact that you are calling populate in the url and the method in the javacode is Populate (different case) make a difference?

also, you should set a success: true in your json

finally, your subject "need help urgent" is not really descriptive of what your problem is. how many other posts on these forums do you see with a similar nondescript subject?

setu01
26 Mar 2011, 5:23 PM
Sorry about that. I would try to change the title for the post and be more descriptive next time.

The populate/Populate is about the servlet. The servlet defined in web.xml is populate that maps to java servlet class Populate.

I did not understand your suggestion about "success: true", where exactly I should put that? are you saying to put this line in jsongrid.js after proxy: new Ext.data.HttpProxy?

thanks for help again, I will look forward for your response.

-Setu

setu01
26 Mar 2011, 5:49 PM
I added the success property to response, but still no luck. here is my new jsongrid.js. I am also attaching the screenshot with the response from firebug.25364

/*!
* Ext JS Library 3.1.1
* Copyright(c) 2006-2010 Ext JS, LLC
* [email protected]
* http://www.extjs.com/license
*/
Ext.onReady(function() {

var store = new Ext.data.JsonStore({
root: 'names',
totalProperty: 'totalRows',
successProperty: 'success',
idProperty: 'threadid',
remoteSort: true,

fields: ['firstName','lastName','age'],

proxy: new Ext.data.HttpProxy({
//url:'http://localhost:8080/ExtjsPaging/Bug',
url:'http://localhost:8080/register/populate',
method:'GET'
})
});


alert("Ext JS is working!:"+store);
var grid = new Ext.grid.GridPanel( {
store : store,
columns : [ {
header : "Last Name",
width : 150,
dataIndex : 'lastName',
sortable : true
}, {
header : "Age",
width : 150,
dataIndex : 'age',
sortable : true
}, {
header : "First Name",
width : 100,
dataIndex : 'firstName',
sortable : true
} ],
renderTo : 'example-grid',
width : 402,
height : 200
});

store.load();
});

and the Populate.java


import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
* Servlet implementation class Populate
*/
public class Populate extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#HttpServlet()
*/
public Populate() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession();
System.out.println("Populate Called!!");
try {
String jsonData = "{success:true, totalRows:3,names:[{lastName:'Patil',age:23,firstName:'Rohan'},{lastName:'Kumar',age:23,firstName:'Arun'},{lastName:'Patilaaa',age:23,firstName:'Basava'}]};";
PrintWriter out = response.getWriter();
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
out.println(jsonData);
out.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}

}

thanks
-Setu