Thymeleaf binding HTML for PDF generation

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Thymeleaf binding HTML for PDF generation

bigal.nz
I have a form which needs to end up as PDF. I am following the guide here : https://www.oodlestechnologies.com/blogs/How-To-Create-PDF-through-HTML-Template-In-Spring-Boot

I am trying to set it so the user fills out the form, the form data is sent to the back-end (Spring) and then inserted into a template and the pdf generator sends it to PDF.
For example:

greeting.html

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
</head>
<body>
<div class="form-check form-check-inline">
<input class="form-check-input checkbox1" type="checkbox" id="section1Checkbox1" value="option1" th:field="${section1Checkbox1}">
<label class="form-check-label" for="section1Checkbox1">Checkbox 1</label>
</div>
</body>
</html>

With fake form data already in the map - controller code for POST:

          // CREATE PDF
          Map<String,String>` data = new HashMap<String,String>();
          data.put("section1Checkbox1","true");
          Map<String, Object> data1 = new HashMap<String, Object>();

        try {
            pdfGenaratorUtil.createPdf("greeting",data);
        } catch (Exception e) {
            e.printStackTrace();
        }
Generates a thymeleaf error:

2018-07-04 11:22:30.570 ERROR 476 --- [nio-8080-exec-2] org.thymeleaf.TemplateEngine : [THYMELEAF][http-nio-8080-exec-2] Exception processing template "greeting": Cannot process attribute '{th:field,data-th-field}': no associated BindStatus could be found for the intended form binding operations. This can be due to the lack of a proper management of the Spring RequestContext, which is usually done through the ThymeleafView or ThymeleafReactiveView (template: "greeting" - line 7, col 102)

org.thymeleaf.exceptions.TemplateProcessingException: Cannot process attribute '{th:field,data-th-field}': no associated BindStatus could be found for the intended form binding operations. This can be due to the lack of a proper management of the Spring RequestContext, which is usually done through the ThymeleafView or ThymeleafReactiveView (template: "greeting" - line 7, col 102)

Suggestions?