Getting this error :
Exception processing template “index”: Exception evaluating SpringEL expression: “bookingForm.name” (template: “index” – line 139, col 29)
org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: “bookingForm.name” (template: “index” – line 139, col 29)
at org.thymeleaf.spring6.expression.SPELVariableExpressionEvaluator.evaluate(SPELVariableExpressionEvaluator.java:292) ~[thymeleaf-spring6-3.1.2.RELEASE.jar:3.1.2.RELEASE]
Booking Form
Time
Date
–>
Comfort
Cheap
<span>Standard</span>
<input name="comfort" value="lux" th:checked="${bookingForm.comfort=='lux'}" type="radio" id="tmRadio2" />
<span>Lux</span>
</div>
<div class="clear"></div>
<span style="color: red;" th:if="${#fields.hasErrors('adult')}" th:errors="*{adult}" ></span>
<div class="fl1 fl2">
<em>Adults</em>
<select name="adult" class="tmSelect auto" data-class="tmSelect tmSelect2" data-constraints="">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
<div class="clear height1"></div>
</div>
<span style="color: red;" th:if="${#fields.hasErrors('children')}" th:errors="*{childre}"></span>
<div class="fl1 fl2">
<em>Children</em>
<select name="children" class="tmSelect auto" data-class="tmSelect tmSelect2" >
<option>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
</select>
</div>
<div class="clear"></div>
<div class="tmTextarea">
<textarea name="message" th:text="${bookingForm.message}" placeHolder="Message" ></textarea>
<span style="color: red;" th:if="${#fields.hasErrors('message')}" th:errors="*{message}" ></span>
</div>
<button class="btn">Submit</button>
</form>
Here Is my Controller##
@RestController
public class MyController
{
private ContactFormServiceImpl contactFormServiceImpl;
@Autowired
public void setContactFormServiceImpl(ContactFormServiceImpl contactFormServiceImpl) {
this.contactFormServiceImpl = contactFormServiceImpl;
}
//Booking Form
@GetMapping(path={"","home","welcome","index"})
public String welcomeView(Model m)
{
m.addAttribute("bookingForm",new BookingForm() );
return"index";
}
@PostMapping("bookingform")
public String bookingForm(@Valid @ModelAttribute("bookingForm") BookingForm bookingForm, BindingResult bindingResult, Model m)
{
if (bindingResult.hasErrors())
{
m.addAttribute("bindingResult", bindingResult);
return "index";
}
System.out.println(bookingForm);
return "redirect:/index";
}
TuShar ThAkre is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1