I can see there are a few question already asked in there, but still I can't find any solution to fix my issue. I am using Spring boot Thymeleafs Template Engine to parse value attribute with Spring Context. Then, I can process PDF generated with flying-saucer-pdf.
I can say the problem is because String is passed to parameter and it is not referent to html file. Error description:
2022-10-11T16:45:58.209+0700 ERROR [THYMELEAF][http-nio-8080-exec-2] Exception processing template "world-check-report": An error happened during template parsing (template: "applicationprocess/world-check-report.html")
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "applicationprocess/world-check-report.html")
at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:235) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parseStandalone(AbstractMarkupTemplateParser.java:100) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:649) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1098) [thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1059) [thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1048) [thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at com.aeon.webadmin.controller.AssessmentController.getWorldCheckStatus(AssessmentController.java:820) [classes/:1.3.5]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_333]
Caused by: java.io.FileNotFoundException: ClassLoader resource "applicationprocess/world-check-report.html" could not be resolved
at org.thymeleaf.templateresource.ClassLoaderTemplateResource.reader(ClassLoaderTemplateResource.java:130) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
My Controller:
@PostMapping(value = "/world-check-info")
public ObjResponseEntity<AmlApplyLoan> getWorldCheckStatus(@RequestBody String aln_id) {
try {
HttpHeaders headers = new HttpHeaders();
AssessmentController assessmentController = new AssessmentController();
ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setPrefix("applicationprocess/");
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode("XHTML");
templateResolver.setCharacterEncoding("UTF-8");
TemplateEngine templateEngine = new TemplateEngine();
templateEngine.setTemplateResolver(templateResolver);
Context ctx = new Context();
ctx.setVariable("message", "TESTING");
//error here when parsing
String htmtContent = templateEngine.process("world-check-report", ctx);
return ObjResponseFactory.success();
} catch (Exception e) {
e.printStackTrace();
}
return ObjResponseFactory.fail();
Template File:
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<div class="content-wrapper" style="padding-left: 120px; font-family: sans-serif;">
<h2 class="page_title" th:text="${message}"></h2>
<h2>CASE REPORT</h2>
</div>
</body>
</html>