package net.sevecek.zakladniwebapp;

import javax.validation.*;
import org.springframework.stereotype.*;
import org.springframework.validation.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.*;

@Controller
public class HlavniController {

    @RequestMapping(value = "/ukazka.html", method = RequestMethod.GET)
    public ModelAndView zobrazUkazku() {
        ModelAndView modelAndView = new ModelAndView(
                "/WEB-INF/view/ukazka.jsp");
        modelAndView.addObject("jmeno", "Java");
        return modelAndView;
    }

    @RequestMapping(value = "/ukazka.html", method = RequestMethod.POST)
    public ModelAndView zpracujUkazku(
            @ModelAttribute("ukazkaForm") UkazkaForm ukazkaForm,
            Errors validacniChyby) {
        if (validacniChyby.hasErrors()) {
            ModelAndView modelAndView = new ModelAndView(
                    "/WEB-INF/view/ukazka.jsp");
            return modelAndView;
        }
        return new ModelAndView("redirect:/index.html");
    }

}
