PDA

View Full Version : problem loading values to my extjs grid using json



kirankumar1231
15 Mar 2011, 12:50 AM
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


this is my home.jsp
a button will be there in this page
on clicking the getvalues.jsp should come
in getvalues.jsp an extgrid should be presen with the content coming from database


<%@

page language="java" contentType="text/html; charset=ISO-8859-1"

pageEncoding="ISO-8859-1"%>
<!


DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<


html>

<


head>

<


meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<


title>Insert title here</title>

</


head>

<


body>

<


form action="getvalues.do">

<


input type="submit"></input>

</


form>

</


body>
</html>


this is my java code
i am populating the values of my db to json object here


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();
Employee empl=new Employee();
empl=empitr.next();
jobj.put("empid",empl.getEmpid());
jobj.put("empname",empl.getEmpname());
json.add(jobj);
}
JSONobj.put("employee",json);
System.out.println(JSONobj.toString());
return mapping.findForward("success");
}
}


this is my getvalues.jsp


<%@


page language="java" contentType="text/html; charset=ISO-8859-1"

pageEncoding="ISO-8859-1"%>
<!


DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<


html>

<


head>

<


meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<


title>Insert title here</title>

<


link rel="stylesheet" type="text/css" href="css/ext-all.css">

<script type="text/javascript" src="js/ext-base.js"></script>
<script type="text/javascript" src="js/ext-all.js"></script>
<


script type="text/javascript">

Ext.onReady(function() {
var store=new Ext.data.JsonStore({
proxy:new Ext.data.HttpProxy({
url:'http://localhost:8080/JsonExample/getvalues.do'
}),
reader:new Ext.data.JsonReader({
root:'employee',
fields:['empid','empname']
})
});
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:store,
width:300,
height:300,
renderTo:Ext.getBody()
});


});


</


script>

</


head>

<


body>

hi
</


body>
</html>


but here the values are not getting populated
please help me in solving this issue
thanks in advance