2012-12-12 22 views
0

道場網格工具通過發出請求到web服務REST像這樣排序由:道場格排序和的RESTEasy JAX-RS

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服務方法的正確方法?

回答

0

我對舊商店/ 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

+0

太棒了!我非常專注於將RESTEasy折服到我的意願,我甚至沒有想到只是讓客戶端做正確的事情。我完全忽略了'sortParam'屬性。謝謝! – awm129