【发布时间】:2012-11-07 11:10:52
【问题描述】:
我是使用这个前端框架应用程序的新手...
我最近开始使用 smartgwt,并且正在使用 Spring MVC 集成构建一个新应用程序。
我正在使用带有 RestDataSource 的 ListGrid(使用带有 mvc:annotation-driven 的 Rest 服务用于纯 JSON)
我可以看到服务正在正常使用,也许我的网格永远不会显示其中的数据。
有人可以帮我吗?
这是我的 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);
}
}
现在是 DataSource 实现
公共抽象类 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 类
公共类 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;
}
}
我的弹簧控制器 PatientControler
@控制器 公共类 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 将参数“数据”作为对象覆盖时,没有任何效果, 返回一个数组 [object Object],[object Object],[object Object],[object Object],[object Object] *
【问题讨论】:
标签: spring datasource smartgwt listgrid