/**
   * Gets the link node of the next page.
   *
   * @param page the pagination object
   * @param contextPath current context path of servlet
   * @return the node
   */
  private Element getNextElement(final Page<?> page, final String contextPath) {
    final Element result = new Element("li");

    String url;
    if (!page.hasNext()) {
      int pageNumber = page.getTotalPages() - 1;
      url = getPagedParams(contextPath, pageNumber < 0 ? 0 : pageNumber, page.getSize());
    } else {
      url = getPagedParams(contextPath, page.getNumber() + 1, page.getSize());
    }

    final Element a = new Element("a");
    a.setAttribute("href", url);
    result.addChild(a);

    final Element icon = new Element("i");
    icon.setAttribute("class", "glyphicon glyphicon-triangle-right");

    a.addChild(icon);

    if (!page.hasNext()) {
      result.setAttribute("class", "disabled");
    }

    return result;
  }
 private void addNextLink(Page<T> page, String pageParam, String sizeParam) {
   if (page.hasNext()) {
     Link link =
         buildPageLink(pageParam, page.getNumber() + 1, sizeParam, page.getSize(), Link.REL_NEXT);
     add(link);
   }
 }
  @RequestMapping("/")
  public String home(
      Model model, HttpSession session, Integer id, @RequestParam(defaultValue = "0") int page) {
    String username = (String) session.getAttribute("username");
    if (username == null) {
      return "login";
    }
    PageRequest pr = new PageRequest(page, 4);
    Page current;

    if (id != null) {
      current = appointments.findOneById(pr, id);
    } else {
      current = appointments.findAll(pr);
    }

    model.addAttribute("nextPage", page + 1);
    model.addAttribute("id", current);
    model.addAttribute("showNext", current.hasNext());
    model.addAttribute("appointments", current);

    return "home";
  }