Я пытаюсь получить некоторые данные формы в шаблоне html и, в конечном итоге, в PDF с помощью iText. На линии:
String processedHtml = templateEngine.process(templateName, ctx);
Я получаю сообщение об ошибке:
2018-09-12 12:13:17.680 ERROR 18264 --- [nio-8080-exec-3] org.thymeleaf.TemplateEngine : [THYMELEAF][http-nio-8080-exec-3] Exception processing template "output.html": An error happened during template parsing (template: "class path resource [templates/output.html]")
Caused by: org.attoparser.ParseException: 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: "output.html" - line 52, col 36) at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:393) ~[attoparser-2.0.4.RELEASE.jar:2.0.4.RELEASE] at org.attoparser.MarkupParser.parse(MarkupParser.java:257) ~[attoparser-2.0.4.RELEASE.jar:2.0.4.RELEASE] at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:230) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE] ... 61 common frames omitted
output.html строка 52:
<input type = "number" class = "form-control inputnid person text-uppercase"
data-property = "nid" id = "nid" placeholder = "NID"
th:field = "*{assessment.nid}"/>
Полный метод:
public class PdfGeneratorUtil {
public static final String BASEURI = "src/main/resources/static";
@Qualifier("templateEngine")
@Autowired
private TemplateEngine templateEngine;
public void createPdf(String templateName, Map map) throws Exception {
Assert.notNull(templateName, "The templateName can not be null");
Context ctx = new Context();
if (map != null) {
Iterator itMap = map.entrySet().iterator();
while (itMap.hasNext()) {
Map.Entry pair = (Map.Entry) itMap.next();
ctx.setVariable(pair.getKey().toString(), pair.getValue());
}
}
String processedHtml = templateEngine.process(templateName, ctx);
PdfWriter writer = new PdfWriter("C:\\tmp\\assessment.pdf");
PdfDocument pdfDoc = new PdfDocument(writer);
ConverterProperties converterProperties = new ConverterProperties().setBaseUri(BASEURI);
HtmlConverter.convertToPdf(processedHtml, pdfDoc, converterProperties);
System.out.println("PDF created successfully");
}
}
Нашел исправление. Как подсказывает трассировка стека, поле: должно быть: отмечено флажками.