【问题标题】:dojo grid sorting and RESTEasy JAX-RSdojo 网格排序和 RESTEasy JAX-RS
【发布时间】:2012-12-12 20:11:20
【问题描述】:

Dojo 网格通过向 REST Web 服务发出请求来实现排序,如下所示:

GET http://server/request?sort(+id)

sort(+id) 是方向 (+/-) 和要排序的列。

目前我正在这样做,它可以工作,但它很难看:

@GET
@Path("request/")
@Produces(MediaType.APPLICATION_JSON)
public Collection<RequestDataWithCurrentStatus> getAllRequests() {
    Collection<RequestDataWithCurrentStatus> col = new ArrayList<RequestDataWithCurrentStatus>();

....

//handle the various types of sorting that can be requested by the dojo widget
String queryString = this.request.getQueryString();

//parse the dojo sort string 'sort(+id)' and sort
...

return col;

}

此方法使用 RESTEasy 注入 @Context private HttpServletRequest request 来访问原始查询字符串。

我觉得我应该能够在我的getAllRequests() 调用中将此查询字符串映射到RESTEasy 的@*Param 注释之一。但是根据 RESTEasy 的documentation,似乎没有一个很好的映射到文档中的螺旋 dojo 查询字符串。我想做这样的事情:

@GET
@Path("request/")
@Produces(MediaType.APPLICATION_JSON)
public Collection<RequestDataWithCurrentStatus> getAllRequests( @DojoQueryParam String sort) {
    ...
}

如何以正确的方式将 dojo 网格查询字符串编组为 RESTEasy Web 服务方法?

【问题讨论】:

    标签: java dojo jax-rs resteasy dojox.grid.datagrid


    【解决方案1】:

    我对旧式商店/dojox 网格缺乏经验,但如果您使用的是 dojo/store/JsonRest:您可以使用sortParam 更改它发送排序参数的方式。无耻地从参考指南中摘录:

    var store = new JsonRest({
      target: "/FooObject/",
      sortParam: "sortBy"
    });
    

    这应该以/foo/bar?sortBy=+id 的形式提出请求。

    http://dojotoolkit.org/reference-guide/1.8/dojo/store/JsonRest.html#sorting

    【讨论】:

    • 太棒了!我非常专注于让 RESTEasy 服从我的意愿,以至于我什至没有想过让客户端做正确的事情。我完全忽略了“sortParam”属性。谢谢!
    猜你喜欢
    • 2014-02-03
    • 1970-01-01
    • 2019-09-25
    • 2020-09-08
    • 2012-02-12
    • 1970-01-01
    • 1970-01-01
    • 2016-06-27
    • 2018-12-08
    相关资源
    最近更新 更多