/**
   * Destroy categoria.
   *
   * @param categoria the categoria
   * @return the model and view
   */
  @RequestMapping(method = RequestMethod.GET, value = "/deletaCategoria")
  public ModelAndView destroyCategoria(final Long id) {
    categoriaService.removeCategoria(id);

    ModelAndView modelAndView =
        new ModelAndView("/categoria/categorias", "categorias", categoriaService.listCategorias());
    modelAndView.setViewName("listaCategorias");
    return modelAndView;
  }
  /**
   * Show categoria.
   *
   * @param id the id
   * @return the model and view
   */
  @RequestMapping(method = RequestMethod.GET, value = "/mostraCategoria")
  public ModelAndView showCategoria(final Long id) {
    ModelAndView modelAndView =
        new ModelAndView("/categoria/categoria", "categoria", new Categoria());

    modelAndView.addObject("categoria", categoriaService.getCategoria(id));
    Categoria categoria = categoriaService.getCategoria(id);
    System.out.println("Subcategorias: " + categoria.getSubcategorias());
    modelAndView.setViewName("mostraCategoria");
    return modelAndView;
  }
  /**
   * Creates the categoria.
   *
   * @param categoria the categoria
   * @param result the result
   * @return the model and view
   */
  @RequestMapping(method = RequestMethod.POST, value = "/criaCategoria")
  public ModelAndView createCategoria(
      @ModelAttribute("categoria") final Categoria categoria, final BindingResult result) {
    categoriaService.createCategoria(categoria);

    ModelAndView modelAndView = new ModelAndView("/categoria/categoria", "categoria", categoria);
    modelAndView.setViewName("mostraCategoria");
    return modelAndView;
  }
  /**
   * Edits the categoria.
   *
   * @param id the id
   * @return the model and view
   */
  @RequestMapping(method = RequestMethod.GET, value = "/editaCategoria")
  public ModelAndView editCategoria(final Long id) {
    Categoria categoria = categoriaService.getCategoria(id);

    ModelAndView modelAndView =
        new ModelAndView("/categoria/editaCategoria", "categoria", categoria);
    modelAndView.setViewName("editaCategoria");
    return modelAndView;
  }
  /**
   * Update categoria.
   *
   * @param categoria the categoria
   * @return the model and view
   */
  @RequestMapping(method = RequestMethod.POST, value = "/editaCategoria")
  public ModelAndView updateCategoria(final Categoria categoria) {
    System.out.println(categoria.getNome());
    System.out.println(categoria.getId());
    categoriaService.updateCategoria(categoria);
    ModelAndView modelAndView =
        new ModelAndView("/categoria/editaCategoria", "categoria", categoria);
    modelAndView.setViewName("mostraCategoria");

    return modelAndView;
  }
  /**
   * Index categoria.
   *
   * @return the model and view
   */
  @RequestMapping(method = RequestMethod.GET, value = "/listaCategorias")
  public ModelAndView indexCategoria() {
    ModelAndView modelAndView =
        new ModelAndView("/categoria/categorias", "categoria", new Categoria());
    PagedListHolder<Categoria> pagedListHolder =
        new PagedListHolder<Categoria>(categoriaService.listCategorias());
    pagedListHolder.setPageSize(20);

    List<Categoria> pagedListCategorias = pagedListHolder.getPageList();

    modelAndView.addObject("categorias", pagedListCategorias);
    modelAndView.setViewName("listaCategorias");

    return modelAndView;
  }