Note that there are some explanatory texts on larger screens.

plurals
  1. POJasperReports & Struts2: custom chart themes
    primarykey
    data
    text
    <p>I'm trying to integrate <em>JasperReports</em> in a web application that runs on <em>Struts2</em>.<br/> I'm using the <em>struts2-jasperreports-plugin (2.3.15)</em>.</p> <p>To do so I added in my <em>struts2.xml</em> the the mapping for the action method and to the image servlet, and I wrote an action that simply takes in input a <em>jrxml</em> source file and compiles the report. <br/> </p> <p>Here is the configuration lines i added in <em>struts2.xml</em></p> <pre><code>&lt;package name="jasperreport" namespace="/jasperreports" extends="jasperreports-default"&gt; &lt;action name="getJasperReport" class="....JasperReportAction" method="getJasperReport"&gt; &lt;result name="success" type="jasper" &gt; &lt;param name="location"&gt;jasper/tmp/${outFile}&lt;/param&gt; &lt;param name="format"&gt;${format}&lt;/param&gt; &lt;param name="imageServletUrl"&gt;/servlets/image?image=&lt;/param&gt; &lt;/result&gt; &lt;/action&gt; &lt;/package&gt; &lt;constant name="struts.action.excludePattern" value="/servlets/image*" /&gt; </code></pre> <p>And added in my <em>web.xml</em> the mapping for the servlet image:</p> <pre><code>&lt;servlet&gt; &lt;servlet-name&gt;ImageServlet&lt;/servlet-name&gt; &lt;servlet-class&gt;net.sf.jasperreports.j2ee.servlets.ImageServlet&lt;/servlet-class&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;ImageServlet&lt;/servlet-name&gt; &lt;url-pattern&gt;/servlets/image&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; </code></pre> <p>The action method is reported here:</p> <pre><code>public class JasperReportAction extends ActionSupport { private java.sql.Connection sqlConnection; private String sourceFile; private String outFile; private String format; private String reportName; private String outputName; public JasperReportAction() { //initialize the connection... } //getters and setters.. public String getJasperReport() { try { String reportPath = "jasper/" + reportName; JasperCompileManager.compileReportToFile(reportPath,"jasper/tmp/" + outputName + ".jasper"); } catch(Exception e) { logger.log("getJasperReport", e); return ERROR; } return SUCCESS; } } </code></pre> <p>And I call the action with a JQuery load:</p> <pre><code>$("#jasperReport").load("url/getJasperReport.action", { "sourceFile": "source.jrxml", "outFile" : "outFile", "format" : "HTML", }); </code></pre> <p>I'm editing my reports with <em>iReports 5.1.0</em> and if I create a report where the charts uses one of the default themes, the report is correctly compiled and it is displayed in my web application.<br/><br> I tried to use a custom template, I've created it and exported the jar using <em>iReport</em> and finally put the theme jar under my WEB-INF/lib folder. </p> <p>When I try to retrieve the report from my application the <em>Struts</em> dispatcher gives me the following error:</p> <blockquote> <p>org.apache.struts2.dispatcher.Dispatcher - Exception occurred during processing request: null java.lang.reflect.InvocationTargetException<br> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) .......</p> </blockquote> <p>I get this error even if i try to open a report that doesn't use the custom theme. Unless I remove the theme jar.<br/><br> It seems that no <em>JasperReports</em> Exception is thrown during the report compilation, since the logger in the catch block doesn't log anything, But the <em>jasper</em> file isn't created.</p> <p>I've put in my WEB-INF/lib the <em>jasperreports-chart-themes</em> jar, I've tried versions 4.0.0 and 5.1.0 but I always get the same error.</p> <p>When I show the report preview in <em>iReport</em> everything works fine.</p> <p>Can someone tell me if I am missing something to do before using custom chart themes?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload