使Dojo网格使用Spring和JSON排序 [英] Making Dojo Grid sort with Spring and JSON

查看:176
本文介绍了使Dojo网格使用Spring和JSON排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个使用Dojo和Spring的webapp。我在应用程序中有一些网格,使用Json dojo商店加载。事情似乎还好,但我现在正在尝试实现排序。根据此链接,dojo不会从商店排序网格,而是将其保留服务器。好的,我想我可以一起工作,但是我遇到了实际遇到的问题。



为了获取数据到我的网格,我们有一个路径,被我的控制器抓住例如,要加载我的作业网格,dojo创建存储和调用/作业/数据。这是我的控制器代码:

  @RequestMapping(value =/ job / data,method = RequestMethod.GET, 
headers =Accept = application / json)
public @ResponseBody列表< Job> getData(){
return jobService.getAll();
}

我使用的是Jackson Json处理器,这样可以很好地返回数据在Json格式化。 Dojo获取数据并显示没有任何问题。当用户单击列标题进行排序时,Dojo会附加到被称为创建类似这样的路径上(例如,在列programName上排序时): / job / data?sort(+ programName)



我的问题是,虽然这段代码仍然调用上面的方法,但我不知道如何获得这个部分的访问权限。我尝试使用 @RequestParam 参数,但不起作用,并且无法完全停止该方法的工作。这是我试过的:

  @RequestMapping(value =/ job / data,method = RequestMethod.GET,
headers =Accept = application / json)
public @ResponseBody列表< Job> getData(@RequestParam(sort)String sort){
log.info(不再到这里);
}

任何人都有任何想法?我想知道部分问题的一部分是否符合?sort = something的正常语法。无论哪种方式,正如我所说,添加 @RequestParam 不会使用这种方法。这就是说,即使方法只是被称为 / job / data 再次没有加入参数,我得到一个错误。请让我知道,如果你需要更多的我,因为这个问题是为了工作,我真的可以使用一些洞察力。谢谢。



更新



我找到一个链接


JsonStore以sort(+ fieldName1,+ fieldName2,-fieldName3,...)的形式发送sort参数。 ..),所以整个事情变成了参数键。这在Spring MVC中处理不方便,因为它需要放弃HttpServletRequest并迭代参数键才能找到以sort开头的代码,而不是使用@RequestParam处理程序参数注释。


所以有人可能会知道我会怎么做?



更新2



任何人?我只是问是否有人能指出我已经找到的解决方案的正确方向。如何从弹簧控制器方法访问HttpServletRequest对象,以便我可以访问Dojo发送的已拧紧排序参数?

解决方案

如果将 HttpServletRequest请求包含在控制器方法中(由spring MVC自动注入),则可以通过以下方式访问不同的参数:

 设置参数= request.getParameterMap()。keySet(); 
for(Object param:parameters){
//这里可以处理参数以检索名称和排序方向
}


So I've got a webapp that uses Dojo and Spring. I've got some grids in the app that are loaded using Json dojo stores. Things seem alright, but I'm now trying to implement sorting. According to this link dojo does not sort grids from Stores, instead it leaves that up to the server. Ok, I assume I can work with that, however I'm running into problems actually doing it.

To get data into my grids, I have them call a path which is caught by my controller. For example, to load my Job grid, dojo creats the store and calls /job/data. Here is my controller code for that:

@RequestMapping(value="/job/data", method=RequestMethod.GET,
        headers="Accept=application/json")
public @ResponseBody List<Job> getData() {
    return jobService.getAll();
}

I'm using the Jackson Json processor so this works well for returning the data formatted in Json. Dojo gets the data and displays it with no problems. When a user clicks on a column header to sort though, Dojo appends onto the path that is called creating something like this (when sorting on column programName for instance): /job/data?sort(+programName)

My problem is that while this code still calls the above method, I'm not sure how to gain access to this tacked on part. I tried using the @RequestParam parameter but that doesn't work and infact stops the method from working altogether. Here is what I tried:

@RequestMapping(value="/job/data", method=RequestMethod.GET,
        headers="Accept=application/json")
public @ResponseBody List<Job> getData(@RequestParam("sort") String sort) {
    log.info("Not getting here anymore");
}

Anyone have any ideas? I'm wondering if part of the problem is that the tacked on part is not following the normal syntax of ?sort=something. Either way, as I said, adding @RequestParam doesn't work anyway with this method. By that I mean that even if the method is just called as /job/data again with no tacked on parameters, I get an error. Please let me know if you need anyting more from me as this problem is for work and I could really use some insight. Thanks.

UPDATE

I did find a link after tons of searching that almost addresses this issue. But of course the Spring guy himself encounters my problem and his code doesn't fix it. He does mention:

JsonStore sends its "sort" parameter in the form of "sort(+fieldName1,+fieldName2,-fieldName3,...)", thus the entire thing becomes the parameter key. This is inconvenient to handle in Spring MVC as it requires dropping down to HttpServletRequest and iterating through parameter keys to find the one beginning with "sort", as opposed to being able to use the @RequestParam handler argument annotation.

So would someone perhaps know how I would do that?

UPDATE 2

Anyone? I'm just asking if someone can point me in the right direction of how to implement the solution I already found. How do I access the HttpServletRequest object from a spring controller method so that I can gain access to the screwed up sort parameter that Dojo sends?

解决方案

If you include HttpServletRequest request to the controller method (it gets automatically injected by spring MVC), you can access the different parameters in the following way:

Set parameters = request.getParameterMap().keySet();
for(Object param : parameters){
  //Here you can process the params to retrieve the names and ordering direction
}

这篇关于使Dojo网格使用Spring和JSON排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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