【问题标题】:smartgwt listgrid RestDataSource not populatingsmartgwt listgrid RestDataSource 未填充
【发布时间】: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


    【解决方案1】:

    从 RestDataSource 传输的数据具有特定格式,在 JavaDoc of the RestDataSource 中进行了描述 您的服务器必须理解请求并返回有效响应。

    目前你的例子似乎不符合合同。

    要调试传入和传出服务器的流量,您可以使用 SmartClient-Console。您可以通过这样的浏览器书签打开它:

    javascript:isc.showConsole()
    

    当然,您需要通过将以下模块添加到您的 gwt.xml 来部署此控制台

    <inherits name="com.smartclient.tools.SmartClientTools"/>
    

    现在转到 RPC 选项卡并检查 Track-RPC

    【讨论】:

    • 谢谢!对于调试的提示。今天早上在阅读您的帖子之前,我已经找到了答案。是的,就像你说的那样......因为我没有使用 smartgwt 服务器端......我必须适应 json { response:{ status:0, startRow:0, endRow:76 返回的格式标准, totalRows:546, data:[ {field1:"value", field2:"value"}, {field1:"value", field2:"value"}, ... 76 条记录... ] } }跨度>
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-11
    相关资源
    最近更新 更多