带有 RestDataSource 和 SpringController 的 Smartgwt [英] Smartgwt with RestDataSource and SpringController

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

问题描述

我已经被困在这里一段时间了.我有一个绑定到 restdatasource 的 smartgwt 小部件 listgrid.我已将其 URL 映射到我的 spring 服务.但是我不知道如何在 spring 服务器端检索 JSON dsrequest.甚至我的调度程序 servlet 也不包含参数.

I have been stuck at this for a while. I have a smartgwt widget listgrid tied to a restdatasource. I have mapped its URLs to my spring services. However I cannot figure out how to retrieve the JSON dsrequest on spring server side. Even my dispatcher servlet does not contain the params.

我的restdatasource如下:

My restdatasource is as follows:

RestDataSource myDS = new RestDataSource() {  
                @Override  
                protected Object transformRequest(DSRequest dsRequest) {
                    dsRequest.setContentType("application/json");
                    JavaScriptObject jso = dsRequest.getData();
            String s1 = JSON.encode(jso);
            return s1;
//                  return super.transformRequest(dsRequest);  
                }  
                @Override  
                protected void transformResponse(DSResponse response, DSRequest request, Object data) {  
                    super.transformResponse(response, request, data);  
                }  
            };

然后在这个数据源上设置操作如下:

Then on this datasource set the operations as follows:

// set the operation on the datasource  
            OperationBinding fetch = new OperationBinding();  
            fetch.setOperationType(DSOperationType.FETCH);  
            fetch.setDataProtocol(DSProtocol.POSTMESSAGE);  
            OperationBinding add = new OperationBinding();  
            add.setOperationType(DSOperationType.ADD);  
            add.setDataProtocol(DSProtocol.POSTMESSAGE);  
            OperationBinding update = new OperationBinding();  
            update.setOperationType(DSOperationType.UPDATE);  
            update.setDataProtocol(DSProtocol.POSTPARAMS);  
            OperationBinding remove = new OperationBinding();  
            remove.setOperationType(DSOperationType.REMOVE);  
            remove.setDataProtocol(DSProtocol.POSTMESSAGE);  
            myDS.setOperationBindings(fetch, add, update, remove);
            myDS.setDataFormat(DSDataFormat.JSON);
//          myDS.setDataProtocol(DSProtocol.POSTMESSAGE);

在数据源中设置一些字段:

Set some fields in the datasource:

// set the values for the datasource
            DataSourceTextField Id = new DataSourceTextField("Id", "Id");
            Id.setPrimaryKey(true);  
            Id.setCanEdit(false);  
            DataSourceTextField name= new DataSourceTextField("name", "Name");
            name.setCanEdit(false);
            DataSourceTextField employeeType= new DataSourceTextField("employeeType", "employeeType");
            employeeType.setCanEdit(true);
            employeeType.setValueMap("Manager", "Associate", "Contractor");

将这些字段设置为数据源:

Set these fields to the datasource:

myDS.setFields(Id, name,employeeType);  
myDS.setFetchDataURL("/rest/myservice/fetch");  
myDS.setAddDataURL("/rest/myservice/add");  
myDS.setUpdateDataURL("/rest/myservice/update");  
myDS.setRemoveDataURL("/rest/myservice/remove");

因此在用户更改employeeType(因为它是下拉列表)的情况下,会发送更新请求.我将 JSON 字符串发送到配置如下的服务器:

So in the case that the user changes the employeeType (because it's a dropdown), an update request is sent. I send the JSON string to the server configured as below:

@Controller
@RequestMapping("/myservice")
public class MyService {
...fetch
...update
    @RequestMapping(value="/update", method=RequestMethod.POST)
    @ResponseBody
    public String update()
    {
         }

我无法理解如何检索 (JSON) dsrequest,因为即使我的 DispatcherServlet 也没有参数(即使我使用 POSTPARAMS).开发人员控制台显示正确发出的请求,但我在服务器端没有收到任何内容.我的 spring servlet 在 web.xml 中配置如下:

I am failing to understand how to retrieve the (JSON) dsrequest because even my DispatcherServlet does not have the parameters (even if I use POSTPARAMS). The developer console shows the request made correctly but I don't receive anything on the server side. My spring servlet is configured as below in web.xml:

<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>    </servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>

我想我遗漏了一些明显的东西,但我找不到它.我是使用 @PathVariable 还是 RequestParams?

I think I am missing something obvious but I can't locate it. Do I use @PathVariable or RequestParams?

推荐答案

找到了我自己的答案.希望这对某人有所帮助.

Found my own answer. Hope this helps someone.

update.setDataProtocol(DSProtocol.POSTPARAMS);

update.setDataProtocol(DSProtocol.POSTMESSAGE);

@Override
protected Object transformRequest(DSRequest dsRequest) {
    JavaScriptObject jso = dsRequest.getData(); 
    String s1 = JSON.encode(jso); 
return s1; 
}

@RequestMapping(value="/update", method=RequestMethod.POST)
@ResponseBody public String update(@RequestBody String json) { }

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

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