-
14 Mar 2011 5:20 AM #1
problem loading values to my extjs grid using json
problem loading values to my extjs grid using json
hello experts
i am loading the values coming from database to my json object using java struts
but the values are not populating in my extjs grid
i am getting an empty grid
this is my code
<%@
pagelanguage="java"contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!
DOCTYPEhtmlPUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<metahttp-equiv="Content-Type"content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<linkrel="stylesheet"type="text/css"href="css/ext-all.css">
<scripttype="text/javascript"src="js/ext-base.js"></script>
<scripttype="text/javascript"src="js/ext-all.js"></script>
<scripttype="text/javascript">
Ext.onReady(
function() {
var store=new Ext.data.JsonStore({
root:'employee',
url:'getvalues.jsp',
fields:['empid','empname']
});
store.load();
var grid = new Ext.grid.GridPanel({
title:'employee information',
coloumns:[{header:"employeeid",width:100,dataIndex:'empid',sortable:true},
{header:"employeename",width:100,dataIndex:'empname',sortable:true}
],
store: store,
renderTo:Ext.getBody(),
width:300,
height:300,
loadMask:true,
renderTo:Ext.getBody()
});
});
</script>
</head>
<body>
</body>
</html>
this is my java code
Code:import java.util.ArrayList; import java.util.Iterator; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import net.*; import net.sf.json.JSONArray; import net.sf.json.JSONObject; public class Json extends Action { @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // TODO Auto-generated method stub ArrayList<Employee> emp=new ArrayList<Employee>(); Myservice serve=new Myservice(); emp=serve.getemployeesservice(); Iterator<Employee> empitr=emp.iterator(); JSONArray json=new JSONArray(); JSONObject JSONobj=new JSONObject(); while(empitr.hasNext()){ JSONObject jobj=new JSONObject(); jobj.put("empid",empitr.next().getEmpid()); jobj.put("empname",empitr.next().getEmpname()); json.add(jobj); } JSONobj.put("employee",json); return mapping.findForward("success"); } }this is my struts config file
<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEstruts-configPUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">
<struts-config>
<action-mappings>
<actionpath="/getvalues"type="Json">
<forwardname="success"path="/getvalues.jsp"></forward>
</action>
</action-mappings>
</struts-config>
this is my complete coding
when i run the program i am getting empty values
please help me in solving this issue
thanks in advance
-
14 Mar 2011 6:04 AM #2
in your code duplicate renderTo existed. so remove one property. and check your store with proxy..this is the sample code
var store = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: 'folder_path/getvalues.jsp', //make sure this is the path where your file exist
method: 'POST'
}),
reader: new Ext.data.JsonReader({
root: 'results',
id: 'Id'
}, [
'Id',
'EmpNumber',
'salary',
'addtess',
'contact',
'email'
])
});
store.load();
use firebug tool to see the database calls and responses...
-
14 Mar 2011 9:43 PM #3
hello shiva
i tried using like this
even then i am getting empty grid
<script type="text/javascript">
Ext.onReady(function() {
var store=new Ext.data.JsonStore({
reader:new Ext.data.JsonReader({
root:'employee',
field:['empid','empname']
}),
proxy:new Ext.data.HttpProxy({
url:'getvalues.do'
})</script>
});
store.load();
var recs=store.getRange();
alert(recs.length);
var grid = new Ext.grid.GridPanel({
title:'employee information',
coloumns:[{header:"employeeid",width:100,dataIndex:'empid',sortable:true},
{header:"employeename",width:100,dataIndex:'empname',sortable:true}
],
store
tore,
width:300,
height:300,
renderTo:Ext.getBody()
});
});
-
14 Mar 2011 9:52 PM #4
install firebug addon for your firefox browser and let me know what it return in firbug
-
14 Mar 2011 10:27 PM #5
yup its not showing any errors
i am very new to this extjs
i could figure out this issue
-
14 Mar 2011 10:42 PM #6
-
14 Mar 2011 10:47 PM #7
hello shiva i have checked the record length
i am getting the rec length as zero
var recs=store.getRange();alert(recs.length);
can u tell me the possible reasons y the values are not getting populated so that i can study more and figure out this issue
-
14 Mar 2011 10:56 PM #8
i think in proxy url:'' you need to give your file full path like (http://example.com/resources/getvalues.jsp).. did you check the output of getvalues.jsp file? is it working fine?
-
14 Mar 2011 11:27 PM #9
yes i have checked that url
but i am not getting any values to my grid
can u check my java code
actually on form action i specified the url as getvalues.do
and on performing neccessary actions in my servlet i am redirecting the page to getvalues.jsp
i tried both the url s i am not getting values to my grid
Similar Threads
-
Loading panel control values with available JSON
By stratton in forum Ext 2.x: Help & DiscussionReplies: 2Last Post: 10 Jun 2009, 5:57 AM -
Problem in json loading in grid - help needed
By kthiru72 in forum Ext 2.x: Help & DiscussionReplies: 1Last Post: 25 Jan 2008, 4:41 AM -
Loading form values from json data
By dlbjr in forum Ext 2.x: Help & DiscussionReplies: 1Last Post: 3 Dec 2007, 10:30 AM -
Having problem loading JSON data into grid
By Blitz in forum Ext 1.x: Help & DiscussionReplies: 8Last Post: 16 Aug 2007, 8:09 AM


Reply With Quote