title: How do validation with thymeleaf and bean validation?
body: <p>I'm trying to perform a simple validation in my view, I know that the jsf it is very simple to do more in the spring mvc is giving me a headache ...
  Can anyone help me with this validation? see what I'm doing wrong ??</p>
  
  <p>my model</p>
  
  <pre><code>package br.com.nextinfo.multimedia.web.model;
  
  import javax.persistence.CascadeType;
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.JoinColumn;
  import javax.persistence.OneToOne;
  import javax.persistence.SequenceGenerator;
  import javax.persistence.Table;
  import javax.validation.constraints.NotNull;
  
  import org.hibernate.validator.constraints.NotBlank;
  
  @Table
  @Entity(name="slideshow")
  public class SlideShow {
  
  private Long condigo;
  
  private String titulo;
  
  private String subTitulo;
  
  private ImagemSlider imagemSlider;
  
  
  @Id 
  @GeneratedValue(generator="codigo",strategy=GenerationType.AUTO) 
  @SequenceGenerator(name = "codigo", sequenceName = "codigo_slideshow")    
  @Column(name = "CODIGO")
  public Long getCondigo() {
      return condigo;
  }
  
  @NotNull
  @NotBlank
  @Column(name = "TITULO" ,nullable = false)
  public String getTitulo() {
      return titulo;
  }
  @OneToOne(cascade = CascadeType.ALL)
  @JoinColumn(name ="CODIGO_IMAGEM")
  public ImagemSlider getImagemSlider() {
      return imagemSlider;
  }
  
  @NotNull
  @NotBlank
  @Column(name = "SUBTITULO" ,nullable = false)
  public String getSubTitulo() {
      return subTitulo;
  }
  
  public void setTitulo(String titulo) {
      this.titulo = titulo;
  }
  
  public void setSubTitulo(String subTitulo) {
      this.subTitulo = subTitulo;
  }
  
  
  public void setImagemSlider(ImagemSlider imagemSlider) {
      this.imagemSlider = imagemSlider;
  }
  
  public void setCondigo(Long condigo) {
      this.condigo = condigo;
  }
  
  
  }
  </code></pre>
  
  <p>my controller </p>
  
  <pre><code>package br.com.nextinfo.multimedia.web.controller;
  
  
  import java.io.IOException;
  import java.util.List;
  
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.validation.Valid;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.Model;
  import org.springframework.validation.BindingResult;
  import org.springframework.web.bind.annotation.PathVariable;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.RequestParam;
  import org.springframework.web.bind.annotation.ResponseBody;
  import org.springframework.web.servlet.mvc.support.RedirectAttributes;
  
  import br.com.nextinfo.multimedia.web.model.ImagemSlider;
  import br.com.nextinfo.multimedia.web.model.SlideShow;
  import br.com.nextinfo.multimedia.web.services.AbstractFactoryService;
  import br.com.nextinfo.multimedia.web.services.CreateSlideShowService;
  import br.com.nextinfo.multimedia.web.services.ImagemServiceDatabase;
  
  @Controller
  @RequestMapping("/arquivosbanco/")
  public class FilesDatabaseController  implements AbstractControllerApp    ,PadraoCrudMetodos&lt;ImagemSlider&gt; {
  
  @Autowired
  private ImagemServiceDatabase imagemService;
  
  @Autowired
  private CreateSlideShowService slideShowService;
  
  @Override
  public String getRequisicaoPadrao(Model model) {
      List&lt;ImagemSlider&gt; lista = this.getAbstractService().realizaPaginacao("0", "10" ,null).getContent();
      model.addAttribute("listaObjetoPageStart", lista);
      model.addAttribute("img", new ImagemSlider());
      return this.getUrlInicial();
  }
  
  @Override
  public String getUrlInicial() {
      return "arquivos/database/listarquivosbancodedados";
  }
  
  @ResponseBody
  @RequestMapping(value = "/img", method = RequestMethod.GET)
  public void showImage(@RequestParam("id") Long id, HttpServletResponse response,HttpServletRequest request)  throws ServletException, IOException {
      response.setContentType("image/jpeg, image/jpg, image/png, image/gif");
      ImagemSlider imgdatabase =  imagemService.getAbstractService().getBean(id);
      if (imgdatabase!=null ) {
          response.getOutputStream().write(imgdatabase.getImage());
          response.getOutputStream().close();
      }
  }
  
  @Override
  public AbstractFactoryService&lt;ImagemSlider&gt; getAbstractService() {
      return imagemService;
  }
  @RequestMapping(value = "/createslideshow/{imagemid}" ,method=RequestMethod.GET)
  public String createslider(@PathVariable("imagemid") Long image,Model model){
      final ImagemSlider img  = this.imagemService.getBean(image);
      model.addAttribute("imgslider", img);
      model.addAttribute("slideshow", new SlideShow());
  
      return "arquivos/createdisplay";
  }
  @RequestMapping(value = "/save" ,method=RequestMethod.POST)
  public String saveSlideShowr( @RequestParam Long imagemid ,@Valid  final SlideShow slideshow,final BindingResult result ,RedirectAttributes redirectAttrs){
  
      ImagemSlider img  = this.imagemService.getBean(imagemid);
      if (result.hasErrors()) {
          redirectAttrs.addFlashAttribute("org.springframework.validation.BindingResult.strategy", result);
          redirectAttrs.addFlashAttribute("slideshow", slideshow);
          return "redirect:/arquivosbanco/createslideshow/"+imagemid;
      }else{
          this.slideShowService.salva(slideshow);
          if (img != null) {
              slideshow.setImagemSlider(img);
              this.slideShowService.salva(slideshow);
          }
      }
      return this.getUrlInicial();
      }
    }
  
     &lt;html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorator="/templates/layouts/principal"&gt;
      &lt;head&gt;
       &lt;title&gt;Criacao slideshow&lt;/title&gt;
    &lt;/head&gt;
   &lt;body&gt;
  
  &lt;div class="container-fluid" layout:fragment="corpopagina"&gt;
      &lt;h3 class="page-header text-center"&gt;Criacao slide show&lt;/h3&gt;
  
  &lt;form id="registration-form" class="form-horizontal"  th:object="${slideShow}" th:action="@{/arquivosbanco/save/?imagemid=}+${imgslider.codigo}"  method="post"&gt;
  
   &lt;!-- Print all errors here!--&gt;
  &lt;div class="col-md-4 col-xs-12"&gt;
      &lt;div class="thumbnail"&gt;
          &lt;img class="img-responsive" th:attr="src=@{'/upload/img?codigo='+${imgslider.codigo}}" width="400" height="400" /&gt;
          &lt;span  class="text-center"&gt;&lt;/span&gt;
          &lt;/div&gt;  
          &lt;div class="caption"&gt;
              &lt;h5&gt;Codigo &lt;span th:text="${imgslider.codigo}" class="badge" style="margin-left:20px"&gt;5&lt;/span&gt;&lt;/h5&gt;
              &lt;h5&gt;Nome &lt;span th:text="${imgslider.nome}" class="badge" style="margin-left:20px"&gt;5&lt;/span&gt;&lt;/h5&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="col-md-8 col-xs-12"&gt;
              &lt;div class="form-group"&gt;
                  &lt;label class="col-xs-3 control-label"&gt;Titulo principal&lt;/label&gt;
                  &lt;div class="col-md-8"&gt;
                      &lt;input type="text" class="form-control" name="titulo"  /&gt; 
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label class="col-xs-3 control-label"&gt;Sub titulo&lt;/label&gt;
                  &lt;div class="col-md-8"&gt;
                      &lt;input type="text" class="form-control input-xs" name="subTitulo" /&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="form-actions"&gt;
                  &lt;label class="col-md-3 control-label"&gt;&lt;/label&gt;
                  &lt;div class="col-md-7"&gt;
                  &lt;button type="submit" class="btn btn-success btn-large"&gt;Salvar&lt;/button&gt;
                  &lt;/div&gt;
                  &lt;div class="col-md-1"&gt;&lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/form&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p></p>
  
  <p>in my controller is validating usually more in view does not show anything how can I solve?</p>
  
  <p>I am quite some time on stackoverflow, most can not find the solution ...</p>