I have a strange issue. Given this controller code:
return CompletableFuture
.supplyAsync(() -> this.acknowledgementTemplatingService.prepareHtmlViewForDocument(offer))
.thenApply(htmlContent -> documentService.generatePdfDocumentFromHtml(htmlContent, ASSETS))
Given this templating code from this.acknowledgementTemplatingService.prepareHtmlViewForDocument(offer)
Using the templating engine from thymeleaf:
ITemplateEngine
Context ctx = new Context();
ctx.setVariable(
ThymeleafEvaluationContext.THYMELEAF_EVALUATION_CONTEXT_CONTEXT_VARIABLE_NAME,
new ThymeleafEvaluationContext(applicationContext, null));
ctx.setVariable("offer", offerDto);
return templateEngine.process("/documents/offer/pdf", ctx);
When this code runs, the template /documents/offer/pdf
cannot be found by the templating engine.
When i refactor this code to the following - calling the template rendering AND the pdf generation in one step:
return CompletableFuture
.supplyAsync(() -> {
String htmlContent = this.serviceDescriptionTemplatingService.prepareHtmlViewForDocument(offerDto);
byte[] pdfContent = documentService.generatePdfDocumentFromHtml(htmlContent, ASSETS);
return pdfContent;
}
The view will be found and will be rendered properly.
What am i doing wrong?