Let's find a solution for an issue in the book Spring in action chapter 3. The web page Design.html provides a list of Ingredients in a form of checkbox. When the user selects the ingredients and post the result. This result is a String of selected objects which is incompatible with the Object "Ingredient. Following is the error stacktrace.

 

Caused by: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'design' available as request attribute at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:153) at org.springframework.web.servlet.support.RequestContext.getBindStatus(RequestContext.java:903) at org.thymeleaf.spring5.context.webmvc.SpringWebMvcThymeleafRequestContext.getBindStatus(SpringWebMvcThymeleafRequestContext.java:227) at org.thymeleaf.spring5.util.FieldUtils.getBindStatusFromParsedExpression(FieldUtils.java:306) at org.thymeleaf.spring5.util.FieldUtils.getBindStatus(FieldUtils.java:253) at org.thymeleaf.spring5.util.FieldUtils.getBindStatus(FieldUtils.java:227) at org.thymeleaf.spring5.processor.AbstractSpringFieldTagProcessor.doProcess(AbstractSpringFieldTagProcessor.java:174) at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:74) ... 67 more

To correct this error, we have to create a Converter class to convert the result from String to ingredient as follow

Add a comment