public class ShortsController {
@RequestMapping(value = "index", method = RequestMethod.GET)
public String showIndex(
Model model,
@RequestParam(value = "id", required = false, defaultValue = "0") int id) {
ShortSectionStrategy strategy = new ShortSectionStrategy(new J2eeConfig());
try {
List<ShortSection> list = strategy.getAll();
List<Shorts> shortsList = new ArrayList<Shorts>();
for (ShortSection shortSection: list) {
Collections.sort(shortSection.getShorts(), new ShortOrderComparator());
shortsList.addAll(shortSection.getShorts());
}
model.addAttribute("list", list);
Shorts displayShort = null;
for (Shorts shorts: shortsList) {
if (shorts.getId() == id) {
displayShort = shorts;
break;
}
}
if (displayShort == null) {
displayShort = shortsList.get(0);
}
model.addAttribute("current", displayShort);
return "/WEB-INF/website/shorts/index.jsp";
} finally {
strategy.close();
}
}