On Monday, January 21, 2013 at 9:04 PM, Douglas Campos wrote:
On Sun, Jan 20, 2013 at 07:29:41AM -0800, danielbevenius wrote:I've been thinking about this and needed to make an update to the controlleras I hade neglected to support returning query parameters in link headers,other than those used for paging.I've looked into Bruno's original suggestion and think it has a hugeadvantage in that the target endpoint class does not have to be changed, andcan simply return a List<?>.route().from("/cars").on(RequestMethod.GET).produces(MediaType.JSON).paged().offset()).to(Cars.class).findCarsBy(param("offset", "0"), param("color"),param("limit", "10"));For cases where the parameters 'offset' and 'limit' are named differentlythey could be configurable:route().from("/cars").on(RequestMethod.GET).produces(MediaType.JSON).paged().offset("myoffset").limitParamName("mylimit").to(Cars.class).findCarsBy(param("offset", "0"), param("color"),param("limit", "10"));Well, I'm not a fan of putting the pagination info on the routesthemselves. Have you researched on using CDI interceptors for this? asit's clearly an infrastructure concern.So what about injecting pagination info via CDI? This means that we'llneed to use instance variables on the Controller class, and decorate itduring instantiation. The paging support could be enabled by using anannotation on the controller method (@Paginated), and the CDI extensionwould take care of wrapping the response/putting the headersaccordingly.public class Cars {private PaginationInfo paginationInfo;@Paginatedpublic List<Car> list() {// fetch offset/limit from this.paginationInfo}}The response would be decorated with the appropriate links.Another option would be to have the method receiving the PaginationInfoparameter, which would eliminate the need for annotations and stuff - ifyou put the parameter on the signature, the response will be wrappedautomagically.Thoughts?For now, I've just ignored support for a total as I think we need more timeto investigate a proper solution for it, if we think it should be supportedat all. The problem with having a callback is that in some situations, likethe one above, that callback would also have to take a query parameter(s) sowe'd need to do more work that like it initial idea were it would bepossible to simply specify a name of a no-args method that returned anint/long.We already got rid of total :)-- qmx_______________________________________________aerogear-dev mailing list