Jump to content
We've recently updated our Privacy Statement, available here ×

ddaitarn304gmail.com

Members
  • Posts

    8
  • Joined

  • Last visited

 Content Type 

Profiles

Forum

Events

Featured Visualizations

Knowledge Base

Documentation (PDF Downloads)

Blog

Documentation (Test Area)

Documentation

Dr. Jaspersoft Webinar Series

Downloads

Everything posted by ddaitarn304gmail.com

  1. Hello, using Jasper Studio 6.4 and Eclipse Neon (4.6.3), when I try to create a "Function Library" I always got this error: java.lang.reflect.InvocationTargetException: An error occurred during the functions library creation at com.jaspersoft.studio.wizards.functions.NewFunctionsLibraryWizard$1.run(NewFunctionsLibraryWizard.java:111) at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:119)Caused by: org.apache.velocity.exception.VelocityException: The specified class for ResourceManager (org.apache.velocity.runtime.resource.ResourceManagerImpl) does not implement org.apache.velocity.runtime.resource.ResourceManager; Velocity is not initialized correctly. at org.apache.velocity.runtime.RuntimeInstance.initializeResourceManager(RuntimeInstance.java:725) at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:263) at org.apache.velocity.app.VelocityEngine.init(VelocityEngine.java:93) at com.jaspersoft.studio.utils.VelocityUtils.getConfiguredVelocityEngine(VelocityUtils.java:50) at com.jaspersoft.studio.wizards.functions.NewFunctionsLibraryWizard$1.run(NewFunctionsLibraryWizard.java:92) ... 1 more[/code]
  2. When putting two or more barcode in a report, you'll get random null pointer exception. It's random, but easy to reproduce: simply put a "codabar" barcode with barcode4j, then add another "codabar" and switch from an item to another here a stak trace from eclipse: eclipse.buildId=4.5.2.M20151021-1000java.version=1.8.0_31java.vendor=Oracle CorporationBootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=it_ITFramework arguments: -product org.eclipse.epp.package.dsl.productCommand-line arguments: -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.dsl.productcom.jaspersoft.studio.propertiesErrorMon Nov 02 12:01:48 CET 2015Problems occurred when invoking code from plug-in: "com.jaspersoft.studio.properties".java.lang.NullPointerException at com.jaspersoft.studio.components.barcode.model.barcode4j.MBarcode4j.getPropertyValue(MBarcode4j.java:227) at com.jaspersoft.studio.components.barcode.model.barcode4j.MEAN13.getPropertyValue(MEAN13.java:107) at org.eclipse.ui.views.properties.PropertySheetEntry.refreshValues(PropertySheetEntry.java:590) at org.eclipse.ui.views.properties.PropertySheetEntry.createChildEntries(PropertySheetEntry.java:253) at org.eclipse.ui.views.properties.PropertySheetEntry.getChildEntries(PropertySheetEntry.java:340) at org.eclipse.ui.views.properties.PropertySheetViewer.updateCategories(PropertySheetViewer.java:1096) at org.eclipse.ui.views.properties.PropertySheetViewer.updateChildrenOf(PropertySheetViewer.java:1267) at org.eclipse.ui.views.properties.PropertySheetViewer.setInput(PropertySheetViewer.java:988) at org.eclipse.ui.views.properties.PropertySheetPage.refresh(PropertySheetPage.java:501) at com.jaspersoft.studio.property.section.JDAdvancedSection$1.run(JDAdvancedSection.java:212) at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:186) at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:145)... [/code]
  3. I think font extension is useless if the font is not installed on client, because if font "extension" is not installed, the print output is awful. For example (before ensure you don't have the "DejaVu" font installed as windows font, If the font is installed, then it works perfectly): report: <?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 6.1.1.final using JasperReports Library version 6.1.1 --><!-- 2015-10-23T14:30:24 --><jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Blank_A4" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="7ee78a0a-3bca-4639-ac2f-edba39f77627"> <queryString> <![CDATA[]]> </queryString> <background> <band splitType="Stretch"/> </background> <title> <band height="79" splitType="Stretch"> <staticText> <reportElement x="10" y="10" width="171" height="51" uuid="62506953-cc8e-4d72-9247-4ab8dbccf9c0"/> <textElement> <font size="24"/> </textElement> <text><![CDATA[Hello World]]></text> </staticText> <staticText> <reportElement x="240" y="10" width="191" height="51" uuid="2368c8a9-29af-4d06-a608-a5e1b67cdc54"/> <textElement> <font fontName="DejaVu Sans" size="24"/> </textElement> <text><![CDATA[Hello World]]></text> </staticText> </band> </title></jasperReport>[/code] If you display in preview, it seems all ok, but when printed (for example on FinePrint): public class Test { public static void main(String[] args) throws JRException { JasperPrint p = JasperFillManager.fillReport("src/test/Blank_A4.jasper", null, new JREmptyDataSource()); JasperPrintManager.printReport(p, false); }}[/code]The image is like this (the second "hello world" is printed in "DejaVu" font):
  4. I know how to add elements by code, for example, to add a text element: JRPrintPage jrPage = new JRBasePrintPage(); txt = new JRBasePrintText(null); jrPage.addElement(txt); but how do I add a component element ? I want to add a barcode4j element, inspecting a designed report I found barcode4j is wrapped as a component inside a "JRBaseComponentElement" , but I don't know how to add manually
  5. With previous version I wrote: JRPrintServiceExporter pse = new JRPrintServiceExporter();pse.setParameter(JRPrintServiceExporterParameter.JASPER_PRINT, Job.jrPrint );pse.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE, Printer.getService() );pse.setParameter(JRExporterParameter.START_PAGE_INDEX, startPage-1);pse.setParameter(JRExporterParameter.END_PAGE_INDEX, endPage-1);pse.exportReport();[/code] With new version, I use "SimplePrintServiceExporterConfiguration" to configure printing, but I don't find how to set start / end page JRPrintServiceExporter pse = new JRPrintServiceExporter();SimplePrintServiceExporterConfiguration configuration = new SimplePrintServiceExporterConfiguration();configuration.setPrintService(printService);pse.setConfiguration(configuration); pse.setExporterInput(new SimpleExporterInput(jasperPrint));pse.exportReport();[/code]
  6. Can Jasper support the java 8 date/time classes ? It seems that you can use LocalDateTime, but pattern string is ignored
  7. When formatting a number you can choose to use an "expression pattern". It's useful because you can use a function to get the real pattern, but I found there is a problem with locale. I want to set up my formatter locale-independent. If you use string pattern, it's not possibile, because, I suppose, Jasper creates DecimalFormat based on report locale. Is there any mode to put a DecimalFormat object directly in "expression pattern" ? Is there an alternative using pattern ?
  8. So, I have installed Jaspersoft Studio as Eclipse plugin, and nice! It's integrated into my application, so I want to create a java class to provide my data for a report. Do a google search and implement a custom JRDataSourceProvider. Let's say, I implement my "RptMyCustomReport", give report fields and data and this works fine. Next step, I want to filter my data based on report input parameter ... but I can't use my custom provider, I have to use QueryExecuterFactory ... but now I loose my original class, or worse, I try to use JRDataSourceProvider (as provider for the report, useful to get report fields) together with QueryExecuterFactory (as language for the report) with no luck. What I wanted, was to give an interface to Jasper for implementing my report, an object that can provide any information to Jasper to build the report, for example, "report field ?" "report input parameters?" "report data for these filters ?" but Jasper doesn't work in this mode. So, to partially simulate that behavior, I found the solution below. First, reports have these elements: - a provider: this is used at design time to get report fields. It's not used a runtime. - a query language to execute the query: this links the QueryExecuterFactory - a query sql: the "only" data stored as is in the report I implement the provider to get the reports fields to Jasper. I put my "RptMyCustomReport" class in the query sql I implement the custom QueryExecuterFactory to parse the sql as java class and create custom data at runtime Here a basic example: // this class shows only that you can pass a parameter to your costum data source public class TestDataSourceFiltered implements JRDataSource { String[] fields; String[][] data; String sampleFilter; private Map<String, Integer> fieldIndex = new HashMap<>(); public TestDataSourceFiltered(String[] fields, String[][] data) { this.fields = fields; this.data = data; for( int i=0; i<fields.length; i++ ) fieldIndex.put(fields[i], i); } public void setParamFilters(Map<String, Object> params) { sampleFilter = (String) params.get("TEST_FILTER_PARAM"); } int pos = -1; @Override public boolean next() throws JRException { for(;;) { pos ++; if( pos >= data.length ) return false; String[] row = data[pos]; if( sampleFilter == null || row[0].equals(sampleFilter) ) return true; } } @Override public Object getFieldValue(JRField jrField) throws JRException { return data[pos][fieldIndex.get(jrField.getName())]; }}[/code] // this is the provider: // design time: get the report fields // design / runtime: return null on data source, to pass the baton to QueryExecuterFactory public class TestDataSourceProviderFiltered implements JRDataSourceProvider { public static class MyField extends JRBaseField { public MyField(String name, String desc, Class<?> clazz) { this.name = name; this.description = desc; this.valueClass = clazz; this.valueClassName = clazz.getName(); } } @Override public boolean supportsGetFieldsOperation() { return true; } // create java class from the query in the report private static TestDataSourceFiltered getInstanceFrom(JRReport report) { if( report == null || report.getQuery() == null ) return null; String s = report.getQuery().getText(); if( s.isEmpty() ) return null; try { return (TestDataSourceFiltered) Class.forName(s).newInstance(); } catch( InstantiationException | IllegalAccessException | ClassNotFoundException e ) { e.printStackTrace(); return null; } } @Override public JRField[] getFields(JasperReport report) throws JRException, UnsupportedOperationException { TestDataSourceFiltered ds = getInstanceFrom(report); if( ds == null ) return new JRField[0]; JRField[] res = new JRField[ds.fields.length]; for( int i=0; i<ds.fields.length; i++ ) { res[i] = new MyField(ds.fields[i], ds.fields[i], String.class); } return res; } // wanted: return null !! The data source will be provided by query executor factory @Override public JRDataSource create(JasperReport report) throws JRException { return null; } // used at design time and at run time public static JRDataSource createWithParams(JRReport report, Map<String, Object> params) throws JRException { TestDataSourceFiltered ds = getInstanceFrom(report); ds.setParamFilters(params); return ds; } @Override public void dispose(JRDataSource dataSource) throws JRException { }}[/code]public class TestQueryExecuterFactoryFiltered extends AbstractQueryExecuterFactory { @Override public Object[] getBuiltinParameters() { return null; } Map<String, Object> unwrap(Map<String, ? extends JRValueParameter> in ) { HashMap<String, Object> res = new HashMap<>(); for( Entry<String, ? extends JRValueParameter> t: in.entrySet() ) { JRValueParameter value = t.getValue(); res.put( t.getKey(), value != null ? value.getValue() : null ); } return res; } @Override public JRQueryExecuter createQueryExecuter(JasperReportsContextjasperReportsContext, JRDataset dataset, Map<String, ? extendsJRValueParameter> parameters) throws JRException { JRValueParameter paramReport = parameters.get(JRParameter.JASPER_REPORT); if( paramReport != null ) { JRReport jreport = (JRReport) paramReport.getValue(); if( jreport != null ) { return new JRQueryExecuter() { @Override public JRDataSource createDatasource() throws JRException { return TestDataSourceProviderFiltered.createWithParams( jreport, unwrap(parameters) ); } @Override public void close() { } @Override public boolean cancelQuery() throws JRException { return false; } }; } } throw new JRException("no provider for dataset: " + dataset.getName()); } @Override public boolean supportsQueryParameterType(String className) { return false; }}[/code] How to use at design time: 1) register TestQueryExecuterFactoryFiltered in Eclipse 2) create a custom report using TestDataSourceProviderFiltered as provider 3) edit "query language" to point to TestQueryExecuterFactoryFiltered 4) create "RptMyCustomReport" derived from TestDataSourceFiltered 5) put in the sql editor the full qualified name of "RptMyCustomReport" 6) exit, save the report (little bug, until you save the report, JSS doesn't give you the query sql) and reopen, click on "read fields", and you get your report fields How to use at runtime public class MainTest { public static void main(String[] args) throws JRException { DefaultJasperReportsContext.getInstance().setProperty("net.sf.jasperreports.query.executer.factory.TEST","test.TestQueryExecuterFactoryFiltered"); Map<String, Object> params = new HashMap<>(); params.put("TEST_FILTER_PARAM", "A"); File sourceFile = new File("./src/test/Blank_A4.jasper"); JasperReport jasperReport = (JasperReport)JRLoader.loadObject(sourceFile); JasperPrint jr = JasperFillManager.fillReport(jasperReport, params,TestDataSourceProviderFiltered.createWithParams(jasperReport, params)); JasperExportManager.exportReportToPdfFile(jr, "./test.pdf"); }}[/code]
×
×
  • Create New...