PDA

View Full Version : problem loading values to my grid



kirankumar1231
16 Mar 2011, 1:33 AM
hello experts
i am new to this extjs
i have been struggling in loading values to my grid

this is my



<script type="text/javascript">
Ext.onReady(function() {
var store=new Ext.data.JsonStore({
proxy:new Ext.data.ScriptTagProxy({
url:'http://localhost:8080/JsonExample/getvalues.html'
}),
root:"employee",
id:'empid',
fields:['empid','empname']
});
store.load();

var colModel = new Ext.grid.ColumnModel([
{header: "empid", width: 120, sortable: true, dataIndex: 'empid'},
{header: "empname", width: 90, sortable: true, dataIndex: 'empname'}
]);

var grid = new Ext.grid.GridPanel({ height:200, width:600, ds:store, cm: colModel});
grid.render(document.body);
grid.getSelectionModel().selectFirstRow();

});
</script>

this is my piece of java code


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);
in the first page when the button is clicked page should be redirected to next jsp with a grid having values coming from database


<form action="getvalues.html">
<input type="submit"/>
</form>

i think there is a problem with the url in the httpproxy
i could not figure out what could be the problem
any one please help me

Grolubao
16 Mar 2011, 1:56 AM
I honestly don't get what you are trying to do...

Why not simply a HttpProxy returning JSON marshalled? You can do it in a AJAX way.
There's better ways to marshall a object into JSON without using that JSONArray JSONObject pattern.


Also, use the autoLoad property instead of manually calling store.load();

kirankumar1231
16 Mar 2011, 2:00 AM
sorry i am new to this extjs and json concepts
actually i wanted to load values from my database to my grid

Grolubao
16 Mar 2011, 2:04 AM
Well, I don't know what technologies you are using, but JSON is just a way of carrying information, pretty much like XML. So you need a way to retrieve your information from the database and then convert it (marshall) into JSON. Take a look at Xstream to marshall your objects into JSON that can be interpreted by ExtJS. Then you create pretty much like you did but instead use a HttpProxy to get the json and the url in your proxy points directly to the method that you created to return JSON.

In our case we use Spring MVC and use annotations to bind the Controller methods to what urls one decides in ExtJS

kirankumar1231
16 Mar 2011, 2:12 AM
well i am using struts
i tried using using httpproxy but it didnot give me the result
i think there is a problem with my url
i dono what should be the url

Grolubao
16 Mar 2011, 2:13 AM
It's easy to know, use Firebug in Firefox and see what your request is returning. If it's JSON then it's correct, if it's HTML then it's not.

kirankumar1231
16 Mar 2011, 2:26 AM
yup its not returning any thing
actually on the form action i specified url as getvalues.html
when the uri is of type html servlet process the request and is redirected to getvalues.jsp

Grolubao
16 Mar 2011, 2:28 AM
Ok, that's because you have a filter that is doing that for you. Change the extension from html to json in the httpproxy url and it should to the trick.

Anyway, this is not a forum to explain the MVC concept. I'll repeat that you know that is working when it's returning json instead of html.

kirankumar1231
16 Mar 2011, 2:44 AM
sorry if i am troubling you much
its not working
i dont know what could be the problem as i am a new to this extjs concepts

kirankumar1231
16 Mar 2011, 3:28 AM
sorry if i am troubling you
itz not working