1. Use DWR
1 directly in Ext. The Manager class of PoJO is
public class CustomerManagerImpl extends HibernateDaoSupport implements CustomerManager {
public PageModel allCustomers() {
PageModel pageModel = new PageModel();
List datas = new ArrayList();
int total ;
String hql = "from Customer";
datas = this.getHibernateTemplate().find(hql);
String countHql = "select count(*) from Customer";
total = ((Long)this.getSession().createQuery(countHql).uniqueResult()).intValue();
pageModel.setDatas(datas);
pageModel.setTotal(total);
return pageModel;
}
}
2, then directly call DWR to obtain the data (dwr.xml code reference later)
var store = new Ext.data.Store({
//data:... here DWR call directly gets
reader:new Ext.data.JsonReader({id:"sn"},fields), //List data
sortInfo:{field:'name', direction:'ASC'}/ / Sort information
});
//DWR EXT integrated sentences, store.loadData(dataslist); Load data
//data returns the PageModel class, with attributes total, datas( List data type)
//There is no need to create a function here, just execute
JCustomerManager.allCustomers(function(data) {
var total = data.total;
var dataslist=data.datas; // The data is List type
store.loadData(dataslist); //Load data
});
3. The DWR here only does one thing, and it will return through the anonymous function The List data of the value is directly injected into the store. The data returned by DWR can be read directly by JsonStore. We need to set the corresponding fields parameters to tell JsonReader which attributes are required.
4, add dwr.xml code
< ;param name="beanName" value="customerManager"/>
< ;/convert>