spring-in-action-5-samples icon indicating copy to clipboard operation
spring-in-action-5-samples copied to clipboard

Chap 3: parse html error name, design.html, jdbc

Open khanhtran94 opened this issue 4 years ago • 0 comments

// 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());

khanhtran94 avatar Apr 16 '20 17:04 khanhtran94