[英]Spring Validation, form doesn't show error message
Why form in my "addcar" view doesn't show message? 为什么我的“ addcar”视图中的表单不显示消息?
My Controller method
@RequestMapping(value = "/add-car", method = RequestMethod.POST)
public String addCar(@ModelAttribute("carDto") @Valid CarDto carDto,
BindingResult bindingResult, ModelMap modelMap) {
if (bindingResult.hasErrors()) {
if (carDto.isDealerCar() == false) {
String status = "userCession";
boolean dealerCar = false;
boolean accepted = false;
int numberOfTestDrives = 0;
modelMap.addAttribute("carDto", new CarDto());
modelMap.addAttribute("status", status);
modelMap.addAttribute("dealerCar", dealerCar);
modelMap.addAttribute("accepted", accepted);
modelMap.addAttribute("numberOfTestDrives", numberOfTestDrives);
return "car/addcar";
}
My Form sample (addcar view) 我的表单示例(addcar视图)
<div class="form-group">
<h3>
<span class="label label-default">Numer VIN</span>
</h3>
<input type="text" class="form-control" th:field="*{vin}" />
<div class="alert alert-warning"
th:if="${#fields.hasErrors('vin')}">
<span th:errors="*{vin}">Error</span>
</div>
</div>
It worked when i just return to my addcar view but it pass without my set values, and i cannot submit form. 当我只是返回到我的addcar视图时,它起作用了,但是没有我的设置值就通过了,并且我无法提交表单。 When it is like above, new form pass but without error message.
如上所示,新表单通过但没有错误消息。
you can try: 你可以试试:
public String addCar(@requestParam (Map) ) { public String addCar(@requestParam(Map)){
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.