related to issue 38518: use renderJR to compile the subreport
authorCarlos Aristu <carlos.aristu@openbravo.com>
Fri, 11 May 2018 15:30:31 +0200
changeset 33950 0c8d2174716f
parent 33949 4fa9879b9647
child 33951 d96625ebe1ee
child 34554 4a5eaa60db14
related to issue 38518: use renderJR to compile the subreport

Refactored the report generation to demonstrate how renderJR method can be used to compile the sub-reports.
src/org/openbravo/erpReports/RptM_Requisition.java
src/org/openbravo/erpReports/RptM_Requisition.jrxml
--- a/src/org/openbravo/erpReports/RptM_Requisition.java	Fri May 11 15:03:03 2018 +0200
+++ b/src/org/openbravo/erpReports/RptM_Requisition.java	Fri May 11 15:30:31 2018 +0200
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2015 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2018 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -26,12 +26,8 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import net.sf.jasperreports.engine.JRException;
-import net.sf.jasperreports.engine.JasperReport;
-
 import org.openbravo.base.secureApp.HttpSecureAppServlet;
 import org.openbravo.base.secureApp.VariablesSecureApp;
-import org.openbravo.client.application.report.ReportingUtils;
 
 public class RptM_Requisition extends HttpSecureAppServlet {
   private static final long serialVersionUID = 1L;
@@ -49,8 +45,9 @@
       String strmRequisitionId = vars.getSessionValue("RptM_Requisition.inpmRequisitionId_R");
       if (strmRequisitionId.equals(""))
         strmRequisitionId = vars.getSessionValue("RptM_Requisition.inpmRequisitionId");
-      if (log4j.isDebugEnabled())
+      if (log4j.isDebugEnabled()) {
         log4j.debug("+***********************: " + strmRequisitionId);
+      }
       printPagePartePDF(response, vars, strmRequisitionId);
     } else
       pageError(response);
@@ -58,25 +55,19 @@
 
   private void printPagePartePDF(HttpServletResponse response, VariablesSecureApp vars,
       String strmRequisitionId) throws IOException, ServletException {
-    if (log4j.isDebugEnabled())
+    if (log4j.isDebugEnabled()) {
       log4j.debug("Output: pdf");
-    String strBaseDesign = getBaseDesignPath(vars.getLanguage());
-
+    }
     HashMap<String, Object> parameters = new HashMap<String, Object>();
-    JasperReport jasperReportLines;
-    try {
-      jasperReportLines = ReportingUtils.compileReport(strBaseDesign
-          + "/org/openbravo/erpReports/RptM_Requisition_Lines.jrxml");
-    } catch (JRException e) {
-      e.printStackTrace();
-      throw new ServletException(e.getMessage());
-    }
-
-    parameters.put("SR_LINES", jasperReportLines);
     parameters.put("REQUISITION_ID", strmRequisitionId);
     renderJR(vars, response, null, "pdf", parameters, null, null);
   }
 
+  @Override
+  protected boolean renderJRShouldCompileSubreports() {
+    return true;
+  }
+
   public String getServletInfo() {
     return "Servlet that presents the RptMRequisitions seeker";
   } // End of getServletInfo() method
--- a/src/org/openbravo/erpReports/RptM_Requisition.jrxml	Fri May 11 15:03:03 2018 +0200
+++ b/src/org/openbravo/erpReports/RptM_Requisition.jrxml	Fri May 11 15:30:31 2018 +0200
@@ -61,6 +61,7 @@
 	<parameter name="LANGUAGE" class="java.lang.String">
 		<defaultValueExpression><![CDATA["en_US"]]></defaultValueExpression>
 	</parameter>
+	<parameter name="SUBREP_RptM_Requisition_Lines" class="net.sf.jasperreports.engine.JasperReport" isForPrompting="false"/>
 	<queryString>
 		<![CDATA[SELECT M_REQUISITION.M_REQUISITION_ID, M_REQUISITION.DOCUMENTNO,
        AD_COLUMN_IDENTIFIER(to_char('AD_User'), to_char(M_REQUISITION.AD_USER_ID), $P{LANGUAGE}) AS REQUESTER,
@@ -200,7 +201,7 @@
 					<subreportParameterExpression><![CDATA[$P{LOCALE}]]></subreportParameterExpression>
 				</subreportParameter>
 				<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
-				<subreportExpression><![CDATA[$P{SR_LINES}]]></subreportExpression>
+				<subreportExpression><![CDATA[$P{SUBREP_RptM_Requisition_Lines}]]></subreportExpression>
 			</subreport>
 		</band>
 	</detail>