I'm creating a Spring Boot, Spring MVC, Hibernate, Jasper report 6 application.
I want to render a PDF exposing it via REST.
This is the controller:
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/ticketBundles/{id}/export", method = RequestMethod.GET)
public ModelAndView exportVoucherB2B(@PathVariable("id") Long id, Locale locale) throws Exception {
TicketBundle ticketBundle = ticketBundleRepository.findOne(id);
if (ticketBundle != null) {
ModelMap model = new ModelMap();
model.addAttribute("datasource", new JREmptyDataSource(1));
model.addAttribute("model", ticketBundle);
//subreports rows
model.addAttribute("rows", new JRBeanCollectionDataSource(ticketBundle.getRows()));
model.addAttribute("footer", footer);
model.addAttribute("taxNote", taxNote);
return new ModelAndView("TicketBundlePdfView-IT", model);
} else {
// TODO
throw new RestNotFoundException("");
}
}
And this is my views.properties to render correctly my ModelAndView:
TicketBundlePdfView-IT.(class)=org.springframework.web.servlet.view.jasperreports.JasperReportsPdfView
TicketBundlePdfView-IT.url=classpath:/reports/tickets/TicketBundle-IT.jrxml
TicketBundlePdfView-IT.reportDataKey=datasource
TicketBundlePdfView-IT.subReportDataKeys=rows
TicketBundlePdfView-IT.subReportUrls=TicketBundleRow-IT.jrxml
According to Spring documentation, this is the right way to do things. Everything work except I'm not able to define the key of subReportUrls.
Checking JasperReportsPdfView I see that subReportUrls is a Properties
/**
* Stores the paths to any sub-report files used by this top-level report,
* along with the keys they are mapped to in the top-level report file.
*/
private Properties subReportUrls;
I am wondering how I can set the key name of that property. On Spring documentation they are speaking about an xml file like this:
<property name="subReportUrls">
<map>
<entry key="ProductsSubReport" value="/WEB-INF/reports/subReportChild.jrxml"/>
</map>
</property>
They didn't mention how to do this with a plain properties file like mine. Is that possibile?