I am actually using Spring 3 MVC and listing data with pagination using PagedListHolder passing the method from my service layer to get all rows from a DB table like this:
PagedListHolder myList = new PagedListHolder(myService.getAll());
And this is my controller code:
public class MyListController implements Controller {
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
String page = request.getParameter("page");
MyService myService = new MyService();
PagedListHolder myList = new PagedListHolder(myService.getAll());
myList.setPageSize(5);
if ("next".equals(page)) {
myList.nextPage();
}
else if ("previous".equals(page)) {
myList.previousPage();
}
ModelAndView modelAndView = new ModelAndView("myList");
modelAndView.addObject("myList", myList.getPageList());
return modelAndView;
}
}
So, this is working perfect but I want to make now a search from myListby using a keyword and the normal way I think could be implementing a method in DAO and Service layers like for example:
...
String keyword = request.getParameter("keyword");
PagedListHolder myList = new PagedListHolder(myService.findByWord(keyword));
...
At this point myList will return all rows from DB that matches my keyword.
What I want to know is if there is a way to search from myList (using myService.getAll(); method and maybe some other method from PagedListHolder) and avoid modifying the DAO and Service layers for not creating extra methods like the one I used in the example above.
Thanks in advance.
There’s no search method in
PagedListHolder. You can check the code here.In addition, if you are using Maven and STS(or maybe also Eclipse), you can check the code by Open Type command. Shortcut is CtrlShiftT.