Hi,
From screens you can print reports using the TablePrintFormAction, EditorPrintFormAction or RunReportAction as described in the documenation.
A report could be printed only with the default template.
But you can create several reports which differ by template and choose between them.
When the PrintFormAction is launched on the screen and multiple applicable for the entity reports exist, the platform offers to chose the desired one in a dialog (see the attached screenshot).
The second way to run reports is to launch them programmatically using the ReportGuiManager. It is more complicated, but provides an ability to specify the template.
The report and template selection should be manually implemented (f.e. by adding a pair of LookupFields to screen).
Look to the following code:
It is a controller of the āCustomerā browse screen
The report is printed by the reportGuiManager.printReport()
The method receives the template code (āCustom_templateā) as a parameter
The ārunReportā may be invoked by button or any other way.
public class CustomerBrowse extends AbstractLookup {
@Inject
private DataService dataService;
@Inject
private Table<Customer> customersTable;
protected ReportGuiManager reportGuiManager = AppBeans.get(ReportGuiManager.class);
public void runReport(Component source) {
Map<String, Object> reportParams = new HashMap<>();
reportParams.put("entity", customersTable.getSingleSelected());
LoadContext<Report> lContext = new LoadContext<>(Report.class);
lContext.setQueryString("select r from report$Report r where r.id = '3ef3a9ed-0eb3-cc2a-be2b-7f175a25bab0' ");
Report report = dataService.load(lContext);
String templateCode = "Custom_template";
reportGuiManager.printReport(report, reportParams, templateCode, null);
}
}
I am getting null point exception while running this code.
What should be r.id in the query string . Will it be same or it may differ?
Below is the error log.
java.lang.NullPointerException
at com.haulmont.cuba.core.app.DataManagerBean.reload(DataManagerBean.java:104)
at com.haulmont.reports.ReportingBean.reloadEntity(ReportingBean.java:606)
at com.haulmont.reports.ReportingBean.createReport(ReportingBean.java:200)
at com.haulmont.reports.ReportServiceBean.createReport(ReportServiceBean.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:85)
at com.haulmont.cuba.core.sys.ServiceInterceptor.aroundInvoke(ServiceInterceptor.java:117)
at sun.reflect.GeneratedMethodAccessor139.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:629)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:618)
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy260.createReport(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.haulmont.cuba.core.sys.remoting.LocalService
public class CustomerBrowse extends AbstractLookup {
@Inject
private DataService dataService;
@Inject
private Table<Customer> customersTable;
protected ReportGuiManager reportGuiManager = AppBeans.get(ReportGuiManager.class);
public void runReport(Component source) {
Map<String, Object> reportParams = new HashMap<>();
reportParams.put("entity", customersTable.getSingleSelected());
LoadContext<Report> lContext = new LoadContext<>(Report.class);
lContext.setQueryString("select r from report$Report r where r.id = '3ef3a9ed-0eb3-cc2a-be2b-7f175a25bab0' ");
Report report = dataService.load(lContext);
String templateCode = "Custom_template";
reportGuiManager.printReport(report, reportParams, templateCode, null);
}
} iām trying to using this operation And iām followed code follows.
Look to the following code:
It is a controller of the āCustomerā browse screen
The report is printed by the reportGuiManager.printReport()
The method receives the template code (āCustom_templateā) as a parameter
The ārunReportā may be invoked by button or any other way.
And i need a service class bean or donāt wantā¦