I am trying to get Multipile Forms to put information into. Those forms are all identical, except in the type information. That is represented in Java in the Type enun interface. All fields of the form should go into a Color object preferrably.
If I do this without the loop, and change, what is given to thymeleaf, it works.
I am running this with Java 1.8.0_231, spring-core 5.1.6, springboot 2.1.4, thymeleaf 3.0.11 Note: this is not the full list!
Below is my current relavent code:
My problem is, that thymeleaf thows the following error:
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/index.html]")
Caused by: org.attoparser.ParseException: Error during execution of processor
'org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor' (template: "index" - line 9, col 31)
Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Error during execution of processor 'org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor' (template: "index" - line 9, col 31)
Caused by: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'colorObj' available as request attribute
this index.html starts at line 7
<th:block th:each="colorObj : ${ColorDevs}">
<form method="POST" action="#" th:action="@{/}" th:object="${colorObj}">
<label th:text="${colorObj.type.displayName}+': '" th:for="${#ids.next('color')}"></label>
<input type=color th:field="*{color}"/>
<br>
<label th:text="'Passwort: '" th:for="${#ids.next('pass')}"></label>
<input type=password th:field="*{pass}"/>
<br>
<input type="hidden" th:field="*{type}"/>
<input type="submit"/>
</form>
<br>
</th:block>
My controllers:
@GetMapping("/")
public String index(Model model){
List<Color> colors = new java.util.ArrayList<>(Collections.emptyList());
for (int i =0;i<Type.values().length;i++) {
colors.add(new Color(Type.values()[i]));
}
model.addAttribute("ColorDevs",colors);
return "index";
}
@PostMapping("/")
public RedirectView color(@ModelAttribute("color") Color color, BindingResult bindingResult){
System.err.println(color.toString());
return new RedirectView("/");
}
Color class
@Data @Getter
public class Color {
private String color = "";
private String pass = "";
private Type type;
public Color(Type type){
this.type=type;
}
}
And lastly my Type class
public enum Type {
COLOR("Color"),
PANE("Pane");
Type(String name){
displayName=name;
}
private final String displayName;
public String getDisplayName() {
return displayName;
}
}