Dojo grids implement sorting by by issuing requests to REST webservices like so:
GET http://server/request?sort(+id)
Where sort(+id) is the direction (+/-) and the column to sort on.
Currently I’m doing this, and it works, but its ugly:
@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;
}
This method uses a RESTEasy injected @Context private HttpServletRequest request to get access to the raw query string.
I feel like I should be able to map this query string to one of RESTEasy’s @*Param annotations in my getAllRequests() invocation. But according to the documentation for RESTEasy, there doesn’t seem to be a good mapping to the screwy dojo query string from the doc. I want to do something like this:
@GET
@Path("request/")
@Produces(MediaType.APPLICATION_JSON)
public Collection<RequestDataWithCurrentStatus> getAllRequests( @DojoQueryParam String sort) {
...
}
How do I marshal dojo grid query strings to RESTEasy webservice methods the right way?
I have scarce experience with the old stores / dojox grids, but in case you are using dojo/store/JsonRest: You can change the way it sends the sort param with
sortParam. Shamelessly snagged from the reference guide:This should make requests on the form
/foo/bar?sortBy=+id.http://dojotoolkit.org/reference-guide/1.8/dojo/store/JsonRest.html#sorting