进出口新使用该前端框架的应用...SmartGWT的listgrid RestDataSource不填充
我最近开始SmartGWT的工作,我用bulding的一个Spring MVC的集成新的应用程序。
我使用的是ListGrid与RestDataSource(消费与MVC REST服务:注解驱动为纯JSON)
我可以看到servaice被消耗正确或许我的网格不会与示其中的数据。
有人可以帮我吗?
这里是我的ListGrid类
公共类ListGrid扩展com.smartgwt.client.widgets.grid.ListGrid {
private final SpringJSONDataSource springJSONDataSource;
public ListGrid(List<DataSourceField> fields) {
this(new PatientDataSource(fields));
}
public ListGrid(SpringJSONDataSource springJSONDataSource) {
this.springJSONDataSource = springJSONDataSource;
init();
}
private void init() {
setAutoFetchData(true);
setAlternateRecordStyles(true);
setEmptyCellValue("???");
setDataPageSize(50);
setDataSource(springJSONDataSource);
}
}
现在有数据源实施
公共抽象类SpringJSONDataSource延伸RestDataSource {
protected final HTTPMethod httpMethod;
public SpringJSONDataSource(List<DataSourceField> fields) {
this(fields, HTTPMethod.POST);
}
public SpringJSONDataSource(List<DataSourceField> fields, HTTPMethod httpMethod) {
this.httpMethod = httpMethod;
setDataFormat(DSDataFormat.JSON);
addDataSourceFields(fields);
setOperationBindings(getFetch());
addURLs();
}
private void addURLs() {
if(getUpdateDataURL() != null)
setUpdateDataURL(getUpdateDataURL());
if(getRemoveDataURL() != null)
setRemoveDataURL(getRemoveDataURL());
if(getAddDataURL() != null)
setAddDataURL(getAddDataURL());
if(getFetchDataURL() != null)
setFetchDataURL(getFetchDataURL());
}
private void addDataSourceFields(List<DataSourceField> fields) {
for (DataSourceField dataSourceField : fields) {
addField(dataSourceField);
}
}
protected abstract OperationBinding getFetch();
protected abstract OperationBinding getRemove();
protected abstract OperationBinding getAdd();
protected abstract OperationBinding getUpdate();
public abstract String getUpdateDataURL();
public abstract String getRemoveDataURL();
public abstract String getAddDataURL();
public abstract String getFetchDataURL();
}
延伸SpringJSONDataSource
公共类PatientDataSource延伸SpringJSONDataSource {
public PatientDataSource(List<DataSourceField> fields) {
super(fields);
setPrettyPrintJSON(true);
}
@Override
protected OperationBinding getFetch() {
OperationBinding fetch = new OperationBinding();
fetch.setOperationType(DSOperationType.FETCH);
fetch.setDataProtocol(DSProtocol.POSTMESSAGE);
DSRequest fetchProps = new DSRequest();
fetchProps.setHttpMethod(httpMethod.toString());
fetch.setRequestProperties(fetchProps);
return fetch;
}
@Override
public String getFetchDataURL() {
return "/spring/fetchPatients";
}
@Override
protected OperationBinding getRemove() {
return null;
}
@Override
public String getRemoveDataURL() {
return null;
}
@Override
protected OperationBinding getAdd() {
return null;
}
@Override
public String getAddDataURL() {
return null;
}
@Override
protected OperationBinding getUpdate() {
return null;
}
@Override
public String getUpdateDataURL() {
return null;
}
类PatientDataSource
}
我的弹簧控制器PatientControler
@Controller 公共类PatienController {
Logger logger = Logger.getLogger(PatienController.class);
@Autowired
private PatientServices patientServices;
@RequestMapping(value = "/patientTest", method = RequestMethod.GET)
@ResponseBody
public Object getTest()
{
return patientServices.getAllPatients();
}
@RequestMapping(value = "/fetchPatients", method = RequestMethod.POST)
@ResponseBody
public Object getAllPatients()
{
return patientServices.getAllPatients();
}
}
PatientServiceImpl
公共类PatientServicesImpl实现PatientServices {
public List<Patient> getAllPatients() {
List<Patient> patients = new ArrayList<Patient>();
Patient patient;
for(int i = 0 ; i < 500 ; i++){
patient = new Patient();
patient.setDateOfBirth(new Date());
patient.setFirstName("Joe");
patient.setMiddleName("Moe");
patient.setLastName("Blow");
patient.setLastConsultation(new Date());
patient.setSex(Sex.M);
patients.add(patient);
}
return patients;
}
}
* 我真的坚持现在,我一直在寻找所有类型的答案....但到目前为止,没有工作时,我试图从我RestDataSource impentation参数“数据”为对象覆盖transformResponse,返回我的数组[目标对象],[目标对象],[目标对象],[目标对象],[对象的对象] *
THX!有关调试的提示。我今天早上在阅读你的文章之前找到了我的答案。是的,就像你说的...因为我没有使用smartgwt服务器端...我必须符合由json返回的格式的标准 { 响应:{ status:0, startRow: 0, endRow:76, totalRows:546, 数据:[ {field1的: “值”,FIELD2: “值”},{ field1的: “值”,FIELD2: “值”},... 76个总记录... ] }} –