0

The Dojo Toolkit uses the JsonRest store to communicate to your server with REST calls. In the dGrid the column headers are sortable. When a column is clicked, there is a call to the server with sort details. I do not know how to handle these calls for sorting in my Java code. Using Jax-RS (Jersey 1.13), how do I build a restful method that matches and responds to the sort query string shown below?

For example, sorting by the "ID" column results in this http request:

/rest/Subcategory/?sort(-subcatId)

I am unclear how to extract the sort query string value using this syntax. I tried @QueryParam("sort") and failed. I am currently searching for sort examples in Java. I also am searching the coding conventions for Restful Services.

medokr
  • 441
  • 1
  • 5
  • 16
  • I was able to solve my problem with this [SO question](http://stackoverflow.com/a/9612720/1653234). – medokr Dec 20 '13 at 16:15

3 Answers3

0

If your URL is something like :-

/rest/Subcategory/?sort=subCatID

The @QueryParam("sort") should work. I have not worked with Jersey much, but have used this many times in CXF which is also another JAX-RS spec implementation.

The CXF's page http://cxf.apache.org/docs/jax-rs-basics.html explains Jaxrs basics nicely. Hope this helps.

RAS
  • 8,100
  • 16
  • 64
  • 86
DKS
  • 51
  • 4
  • I thought the same. However, Dojo Framework uses the formatting shown above: `?sort(-subcatId)` or `?sort(+subcatId)`. – medokr Dec 20 '13 at 15:46
0

You can inject the @ServletRequest as a parameter of your resource method, and then retrieve the query string:

@GET
public Response getSubCategory(@Context HttpRequestServlet request) {
    ...
    request.getQueryString();
    ...
}
Xavier Coulon
  • 1,580
  • 10
  • 15
0

In order to get Dojo to send it as a query param (i.e. with the sort=+someValue or sort=-someValue make sure you set

"Content-Type":"application/json"
"charset":"UTF-8"

var TrackableRest = declare([Rest, Trackable]);
    var interceptStore = new TrackableRest({
        target: 'rest/intercepts/', 
        accepts: "application/json",
        sortParam: 'sort',         
        rangeStartParam: 'offset',
        rangeCountParam: 'limit',
        headers:{
            'Accept': "application/json",
            'Content-Type':"application/json",
            'charset':"UTF-8"             
        },
        idProperty: 'id'
    });