spring-in-action-5-samples
spring-in-action-5-samples copied to clipboard
Chap 3: parse html error name, design.html, jdbc
// DesignTacoController.java
@GetMapping
public String showDesignForm(Model model) {
List<Ingredient> ingredients = new ArrayList<>();
ingredientRepo.findAll().forEach(i -> ingredients.add(i));
Type[] types = Ingredient.Type.values();
for (Type type : types) {
model.addAttribute(type.toString().toLowerCase(),
filterByType(ingredients, type));
}
return "design";
}
design.html
<h3>Name your taco creation:</h3>
<input type="text" th:field="*{name}"/>
<span class="validationError"
th:if="${#fields.hasErrors('name')}"
th:errors="*{name}">Name Error</span>
<br/>
root cause:
you need add model taco before return on showDesignForm
model.addAttribute("design", new Taco());