Why form in my "addcar" view doesn't show message?
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)
<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. When it is like above, new form pass but without error message.
you can try:
public String addCar(@requestParam (Map) ) {
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.