2012-11-19 53 views
0

進出口新使用該前端框架的應用...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,返回我的數組[目標對象],[目標對象],[目標對象],[目標對象],[對象的對象] *

回答

0

其從RestDataSource傳送的數據具有在該JavaDoc of the RestDataSource 你的服務器說明必須理解該請求,併發送回一個有效的響應特定的格式。

目前你的例子似乎並沒有履行合同。

要調試的流量發送到從服務器可以使用SmartClient的控制檯。您可以通過瀏覽器書籤像這樣打開它:

javascript:isc.showConsole() 

,因爲你需要通過添加下列模塊安裝到您gwt.xml

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

部署此控制檯現在去RPC標籤和檢查履帶的RPC

+0

THX!有關調試的提示。我今天早上在閱讀你的文章之前找到了我的答案。是的,就像你說的...因爲我沒有使用smartgwt服務器端...我必須符合由json返回的格式的標準 { 響應:{ status:0, startRow: 0, endRow:76, totalRows:546, 數據:[ {field1的: 「值」,FIELD2: 「值」},{ field1的: 「值」,FIELD2: 「值」},... 76個總記錄... ] }} –