smartgwt listgrid RestDataSource未填充 [英] smartgwt listgrid RestDataSource not populating

查看:76
本文介绍了smartgwt listgrid RestDataSource未填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是使用此前端框架应用程序的新手...

Im new using this front end framework application...

我最近开始与smartgwt一起工作,并且正在与Spring MVC集成一起构建新的应用程序。

I recently started to work with smartgwt and i'm bulding a new application with a Spring MVC integration.

我正在使用带有RestDataSource的ListGrid(使用具有 mvc:annotation-driven 的Rest服务(用于纯JSON)

I'm using a ListGrid with a RestDataSource (Consume the Rest service with mvc:annotation-driven for plain JSON)

我可以看到servaice正确使用了,也许我的网格永远都没有显示数据。

I can see that the servaice gets consuming properly perhaps my grid is never shown with the data in it.

有人可以在这里帮我吗?

Can someone help me here ?

这是我的 ListGrid

Here's my ListGrid class

公共类ListGrid扩展了com.smartgwt.client.widgets.grid.ListGrid {

public class ListGrid extends 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);
}

}

现在有数据源实现

Now there's the DataSource implmentation

公共抽象类SpringJSONDataSource扩展了RestDataSource {

public abstract class SpringJSONDataSource extends 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类

The class PatientDataSource that extends SpringJSONDataSource

公共类PatientDataSource扩展SpringJSONDataSource {

public class PatientDataSource extends 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

My spring controller PatientControler

@Controller
公共类PatienController {

@Controller public class 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

PatientServiceImpl

公共类PatientServicesImpl实现PatientServices {

public class PatientServicesImpl implements 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实例化参数 data作为对象来覆盖transformResponse时,什么都没起作用,返回了我数组[object Object],[object Object],[object Object],[object Object],[object Object] *

推荐答案

从RestDataSource传输的数据具有 RestDataSource的JavaDoc
您的服务器必须了解该请求并发送回有效的响应。

The Data which is transferred from the RestDataSource has a specific format which is described in the JavaDoc of the RestDataSource Your server must understand the request and send back a valid response.

目前,您的示例似乎还没有履行合同。

At the moment your example doesn't seem to honour the contract.

要调试往返服务器的流量,可以使用SmartClient-Console。您可以通过如下浏览器书签打开它:

To debug the traffic send to and from your server you can use the SmartClient-Console. You can open it by a browser bookmark like this:

javascript:isc.showConsole()

原因是,您需要通过在 gwt.xml

Of cause you need to deploy this console by adding the following module to your gwt.xml

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

现在转到 RPC 标签并选中 Track-RPC

这篇关于smartgwt listgrid RestDataSource未填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆