One, the direct use of DWR in ext
The 1,pojo Manager class is
Copy Code code as follows:
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 direct call to Dwr to get the data (Dwr.xml Code reference later)
Copy Code code as follows:
var store = new Ext.data.Store ({
Data: ... Here's a dwr call directly get
Reader:new Ext.data.JsonReader ({ID: "sn"},fields),//list data
Sortinfo:{field: ' Name ', direction: ' ASC '}//sort info
});
Dwr+ext integrated sentences, Store.loaddata (dataslist); Loading data
Data returns the Pagemodel class, the property is Total,datas (list data type)
There's no need to create a function to execute directly
Jcustomermanager.allcustomers (function (data) {
var total = data.total;
var Dataslist=data.datas; Data is List type
Store.loaddata (dataslist); Loading data
});
3, here's the DWR only do one thing, through the anonymous function, will return the value of the list data directly injected to the store. The data returned by DWR can be read directly by Jsonstore, and we need to set the corresponding fields parameters to tell Jsonreader what properties are required.
4, supplemental Dwr.xml code
Copy Code code as follows:
<dwr>
<allow>
<!--dwr+spring injection mode-->
<c reate creator= "Spring" javascript= "Jcustomermanager" >
<param name= "Beanname" value= "Customermanager"/> The class used by the
</create>
<!--uses the converter-->
<convert match= "Com.graduate.crm.PageModel converter=" Beans ></convert>
<convert match= "Com.graduate.crm.model.CompanyCustomer" converter= "Bean" >< /convert>
</allow>
</dwr>