我是struts 2和extjs的新手。我想显示来自struts到extjs网格的数据 那么,我们怎么能显示出来呢? 我的struts.xml是
<package name="example" extends="json-default" >
<action name="gridDisplay" class="sample.extjs.StudentList" method="GridData">
<result type="json" />
</action>
</package>
java代码
public String GridData() throws Exception{
// this list returns all the name of student in arraylist
List listdata = studentInfo.listNameDetails();
if(!listdata.isEmpty()){
JSONObject myobje = new JSONObject(); // json object
myobje.put("title", listdata); // create a json of the student list
//ServletActionContext.getResponse().getOutputStream().println(myobje+"");
// also tried this but didnt work
return myobje.toString();
}else{
ServletActionContext.getResponse().getOutputStream().print("0");
return null;
}
}
extjs代码是
Ext.onReady( function() {
Ext.define("StudentList",{
extend:"Ext.data.Model",
fields:["firstName","lastName","Gender"]
});
var ListStore = Ext.create("Ext.data.JsonStore",{
model: "StudentList",
proxy: {
type:'ajax',
url:"/gridDisplay",
reader:{
type:"json",
root:"title"
}
}
});
ListStore.load();
Ext.create("Ext.grid.Panel",{
title:"List Of Student",
store: ListStore,
renderTo: Ext.getBody(),
height:250,
width:500,
columns:[
{text: 'firstName', dataIndex: 'firstName', flex: 2},
{text: 'lastName', dataIndex: 'lastName', flex: 2},
{text: 'Gender', dataIndex: 'Gender', flex: 2},
]
});
});
这是我的extjs代码,我想在网格中显示数据。 我在json formate中对struts的调用是否正确?
感谢您的回复