I have an HTML file in themes/layouts. I am displaying it using an HtmlBox. I would also like to be able to programmatically access the html in the file and save it to a file or print it.
Is there anyway to get the file or the file contents from the HtmlBox?
How do you specify the html file in the theme as a resource and then use the getResourceAsString or getResourceAsStream functionality?
What would the document path be for something in themes/layouts when using the following?
How can you get the html in the file to print to the printer or save? I am using the ExportDisplay example but all that seems to do is open the html in a new tab?
Incidentally, the save button is in a dialog window opened with openWindow(“name”, WindowManager.OpenType.Dialog) in case that might make a difference.
public class ExtAppMainWindow extends AbstractWindow {
@Inject
private Embedded reportEmbedded;
@Override
public void init(Map<String, Object> params) {
super.init(params);
String report = "<html><body><h1>Invoice</h1></body></html>";
reportEmbedded.setSource("report-" + UUID.randomUUID() + ".html",
new ByteArrayInputStream(report.getBytes(StandardCharsets.UTF_8)));
}
}
I do not recommend to read any resources from a theme because their location can depend on deployment configuration.
If you want to read something from resources you can use Resources interface that allows you to read resources from class path and override them using conf directory.
I’ve switched to using Embedded but am still having some issues with the Resources interface. I’ve got it working when I put the html file in the code directory and specify the full path – i.e.
Also, how can you get the html in the file to print to the printer or save? I am using the ExportDisplay example but all that seems to do is open the html in a new tab?
If you want to use Resources to access data from a screen then you have to add the data directory to web module sources, because core is a separate application inside of Tomcat and you cannot load resources of core from web context.
Usually there is no need to change cuba.confDir property. It is set to tomcat/conf/ by default and used only for configuration overriding and hot deployment.
You can force HTML page download using ExportFormat.OCTET_STREAM: