Hello Everyone
I have a situation that I cannot explain or correct and need some assistance.
Operating System: macOS Catalina 10.15.7
Browser: Safari Version 14.0.1 (15610.2.11.51.10, 15610)
File System: Case-Sensitive Journaled HFS+ (APFS)
Datebase: MySQL 8.0.19
CUBA Platform version: 7.2.10
CUBA Studio plugin version: 14.3-193
IntelliJ version: CUBA Studio 2019.3
Use Case: I am displaying a preview of the user’s input text, after it’s been processed with a FreeMarker template, in a textArea before I send it as an email so that the user can examine the complete message.
Problem: When I use the email sending method described in the developer’s guide, the user’s text is correctly processed with my FreeMarker template and the mail is sent as expected. My FreeMarker template is located at this path:
/modules/core/src/com/company/nfm/templates/initialContact.en.txt
and my source code (without all of the variables) is as follows and does work correctly:
String templatePath = “com/company/nfm/templates/initialContact.en.txt";
EmailInfo emailInfo = EmailInfoBuilder.create()
.setAddresses(toAddress)
.setCaption(subject)
.setFrom(null)
.setBcc(bccAddress)
.setSendInOneMessage(true)
.setBodyContentType(EmailInfo.TEXT_CONTENT_TYPE)
.setTemplatePath(templatePath)
.setTemplateParameters(Collections.singletonMap(“contact”, contact))
.build();
emailService.sendEmailAsync(emailInfo);
However, when I use the following code to explicitly process the text with my FreeMarker template for previewing, the “template” string returned by resources.getResourceAsString(templatePath) is always null …
private void previewMessage() {
String previewStr;
String templatePath = “com/company/nfm/templates/initialContact.en.txt”;
String template = resources.getResourceAsString(templatePath);
if (template == null) {
previewStr = messages.getMessage(“com.company.nfm.web.screens.contact”, “contactTemplatePathError”) + " " + templatePath;
contactPreviewTextArea.setValue(previewStr);
return;
}
previewStr = TemplateHelper.processTemplate(template, Collections.singletonMap(“contact”, contact));
contactPreviewTextArea.setValue(previewStr);
}
…unless I copy my template to the following path:
/deploy/app_home/app/conf/com/company/nfm/templates/initialContact.en.txt
If I copy my template to the deployment path my preview text is generated as expected.
I do not understand why emailService.sendEmailAsync(emailInfo) finds my template at the “/modules/core/src/com/company/nfm/templates/initialContact.en.txt” but my preview function does not and requires that I copy the template to the deployment path.
The source code of processBodyTemplate(), directly below, uses the exact same method that my preview does and it works correctly, otherwise my email would not be formatted correctly. Therefore, I cannot understand where the path reference is being manipulated, so that the deployment path is needed for my preview.
Can someone please tell me what I am missing or doing wrong?
Many thanks in advance.
Happy Holidays & Best regards
Chris