| Issue 154: | Trying to use limit interface without using tablefacade in the controller. | |
| 1 person starred this issue and may be notified of changes. | Back to list |
Hi,
i wish to avoid using the TableFacade in the controller, since we were
mainly sticking to the jsp tag libs to display the jmesa grid. but the
issue is to actually get the user actions (filter, sort, and pagination)
from the request. The following is the code tried out. Is it a correct way
of doing it, or is there a better approach.
public List<Hotel> getHotels(SearchCriteria criteria, HttpServletRequest
request, ModelMap model) {
List<Hotel> hotelsList = bookingService.findHotels(criteria);
int totalSize = hotelsList.size();
int maxRows ;
LimitActionFactory fact = new LimitActionFactoryImpl("tag",
request.getParameterMap());
if (fact.getMaxRows() != null) {
maxRows = fact.getMaxRows() ;
criteria.setPage(fact.getPage()-1);
criteria.setPageSize(maxRows);
} else {
maxRows = 10 ;
criteria.setPage(0);
criteria.setPageSize(maxRows);
}
// this is the bad part. you have to run again to get the items
required now
hotelsList = bookingService.findHotels(criteria);
model.addAttribute("limit", buildLimit(fact, request, totalSize,
maxRows));
return hotelsList ;
}
private Limit buildLimit(LimitActionFactory fact, HttpServletRequest
request, int totalSize, int maxRows) {
WebContext webContext = new HttpServletRequestWebContext(request);
LimitFactory limitFactory = new LimitFactoryImpl(fact.getId(),
webContext);
Limit limit = limitFactory.createLimitAndRowSelect(maxRows, totalSize);
return limit ;
}
Oct 12, 2008
#1
ajay.mah...@gmail.com
Oct 13, 2008
From a design perspective the Limit interface works great. You can package the information however you want for your service code, but from a controller perspective the TableFacade and Limit are very easy to work with. I would not use the LimitActionFactory either, but just work with TableFacade as it offers a very nice abstraction over the API. https://code.google.com/p/jmesa/wiki/LimitTutorial
Labels:
-Type-Defect Type-Other
Oct 13, 2008
Thanks for the reply and URL. but i still have a doubt. If I am using the jsp tag libs to construct the jmesa in the JSP, then using TableFacade in the controller may not be needed. this is because both, the items and obtained from the service layer has to be set in the Model (request.setAttribute) to be used by the jmesa tag in the JSP. so, then why create the TableFacade in the first place in the controller. Perhaps i could be wrong here, but i see table facade as more of a view thing (html table) and hence perhaps be kept within JSP and not exposed to the controller. In the controller, it is just a matter of extracting user actions and hence the use of LimitActionFactory.
Oct 13, 2008
From my perspective you could use either one. The TableFacade is meant for convenience and another layer of abstraction. For instance if you use the (recommended) TableFacadeFactory to build the TableFacade then you get things like Spring integration. Granted, at the present time there are no features you would need that for, but you may in the future. In the controller you would just be creating a TableFacade to get a Limit object. You would not be declaring any columns or anything else that you do in your tags. On a different note the Limit is meant to be modified, persisted, and passed around if needed. That is why modifying the Limit and passing it to the view is a very natural thing to do with JMesa. I would not pass the Limit back to the service either, but I do not have any issues with creating a TableFacade (or LimitFactory) to work with how the user interacted with the table. I also think passing a Limit to the view is pretty elegant actually. The Controller is supposed to pass the model for the view. In this case part of the model is the Limit.
Oct 14, 2008
thanks Jeff, suggestions appreciated.
Oct 14, 2008
(No comment was entered for this change.)
Status:
Invalid
|