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

thangalin

Members
  • Posts

    322
  • 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 thangalin

  1. For Jaspersoft Studio 6.2, the solution outlined here appears to work. Create Variable Create a variable as follows: Create a variable called `V_CURRENT_PAGE_NUMBER` Select the variable to open its properties (illustrated below) Set **Expression** to: `1` Set **Initial Value Expression** to: `$V{PAGE_NUMBER} + 1` Set **Reset type** to: `Page` These settings are illustrated in the following figure: http://i.stack.imgur.com/epVPG.png Setting the **Expression** to `1` prevents its value from being `null`. That is, if the footer shows *Page **null** of 4* it probably means that the **Expression** hasn't been set. The variable is created. Add Page Footer Add a **Page Footer** band as follows: Select the report in the outline panel Check **Summary With Page Header And Footer** to ensure the page footer appears on the summary page. Add a **Page Footer** band. The footer is added. Create Text Field Create a text field as follows: Drag and drop a *single text field* onto the **Page Footer** band. Select the text field. Set **Expression** to: `msg("Page {0} of {1}", $V{V_CURRENT_PAGE_NUMBER}, $V{PAGE_NUMBER})` Set **Evalutation Time** to: `Auto` These settings are illustrated in the following figure: http://i.stack.imgur.com/F8Nih.png The single text field is created. Preview Report For a report with three pages plus a summary page, previewing the report shows: http://i.stack.imgur.com/CQtk5.png The summary page shows: http://i.stack.imgur.com/jYXlL.png See also: http://stackoverflow.com/a/37552266/59087
  2. This answer makes the following assumptions: The class files and resource bundles are located in the "build" directory (should created by default when writing custom Java classes).The distribution directory for the Java archive will be named "dist".The images used by the reports are in an "images" directory and in SVG format.The report templates have been compiled and are in the main project folder.Now: In the project folder create a file named "build_dist.xml"Copy the following content into build_dist.xml:<?xml version="1.0"?><project name="DistributionLibrary" default="dist" basedir="."> <description>Archives templates, bundles, class files.</description> <property name="build" location="build" /> <property name="dist" location="dist" /> <target name="dist" description="Build distribution archive."> <mkdir dir="${dist}" /> <jar destfile="${dist}/templates.jar"> <fileset dir="${build}" includes="**/*" /> <fileset dir="." includes="images/*.svg" /> <fileset dir="." includes="**/*.jasper"/> </jar> </target></project> Right-click on the project name.Select Properties.Select Builders.Click New.Select Ant Builder.Click OK to display the Edit Configuration dialog.Set Buildfile to: ${project_loc}/build_dist.xmlSet Base Directory to: ${project_loc}Click the Targets tab.Click Set Targets beside "After a 'Clean'".Uncheck dist, if it is checked.Click OK.Click Set Targets beside "Manual Build".Check dist, if it is unchecked.Click OK.Click OK to close the Edit Configuration dialog.Click OK to close the Project properties dialog.The archive is now bulit automatically after each successful project build. Try it as follows: Select Project >> Clean.Click OK.In the Console panel you should see BUILD SUCCESSFUL. Once the build is successful, the dist directory will contain a file called templates.jar that contains an archive that can be used as a resource for reports (in a Java application).
  3. What are the steps to create a distribution library that contains all the: Report imagesInternationalized resource bundlesClass files (for custom functionality)Report templates
  4. Changed Resolution from Works as Designed to Reopened Changed Status from Resolved to Feedback Requested In my experience, many people often conflate .jrxml files with .jasper files, thinking both are needed at run-time, when only the .jasper files are needed.This leads to a security hole whereby the .jrxml files are often posted to a public web server. Consequently, the underlying SQL calls are exposed by downloading text-based .jrxml files. Once the SQL is exposed, the database type (e.g., Oracle, PostgreSQL, MySQL) and parts of the database schema (tables, views, columns) are easy to discover.I'd like to see the ability to create a build directory that is added to the Java Build Path (e.g., ProjectName/build). This directory is then added to the CLASSPATH so that when the reports are run, they can be found (including sub-reports).To make everyone happy, this could an option that users have to enable manually. By default, the .jasper files go into the .jrxml file directory, but advanced users can keep them in a separate build directory. Note that this has positive implications for the integrated Team (repository) support, as files in the build directory aren't added to the repository by default. (This is the expected behaviour for a repository: interim build artifacts aren't pushed to the repository.) As it stands, by default, the .jrxml AND .jasper files are added to the repository, which requires manual intervention to suppress (continually, too, as additional sub-reports generate additional .jasper files that must be subsequently ignored).
  5. See: http://community.jaspersoft.com/questions/992316/canonical-step-step-guide-global-date-format-jaspersoft-studio-6x
  6. See: http://community.jaspersoft.com/questions/992316/canonical-step-step-guide-global-date-format-jaspersoft-studio-6x
  7. See http://community.jaspersoft.com/questions/992316/canonical-step-step-guide-global-date-format-jaspersoft-studio-6x
  8. See: http://community.jaspersoft.com/questions/992316/canonical-step-step-guide-global-date-format-jaspersoft-studio-6x
  9. The following seems to work: Click Window >> PreferecesSelect CapabilitiesCheck DevelopmentClick OKNext: Open the Project ExplorerRight-click Project nameSelect PropertiesSelect Java Build PathClick the Source tabClick Add FolderSelect Create New FolderSet Folder Name to: srcClick FinishSelect srcClick OKSet Default output folder: Project Name/buildClick OKCreate a report as usual (with a text field that uses a date, either a parameter or a field), then: Select the report in the Outline panelOpen the Properties panelSet Format Factory Class to: com.company.reports.ReportFormatFactoryNext, create some source code inside the "src" directory in a package (folder) named "com.company.reports". Paste the following into a file named "ReportFormatFactory.java" that is saved in that directory: import java.text.DateFormat;import java.util.Locale;import java.util.TimeZone; import net.sf.jasperreports.engine.util.DefaultFormatFactory; /** * Delegates creation of date and number formatters to JasperReports' default * formatters. This class ensures that dates are formatted consistently across * all reports. */public class ReportFormatFactory extends DefaultFormatFactory { /** * Returns a DateFormat instance that creates dates in YYYY/MM/dd format. * * @param pattern Unused. * @param locale Passed to the DefaultFormatFactory instance. * @param timezone Passed to the DefaultFormatFactory instance. * * @return An object that can format dates. */ @Override public DateFormat createDateFormat( String pattern, Locale locale, TimeZone timezone ) { return super.createDateFormat( "YYYY/MM/dd", locale, timezone ); }}When you run the report, the date should be formatted as YYYY/MM/dd. If you want to change the format (e.g., to "dd/MM/YYYY"), update the date format line in the source code and then restart Jaspersoft Studio (the classloader does not seem to reload the ReportFormatFactory class after modification). To avoid having to restart each time the date format changes, use a resource bundle: Create a new project folder called i18n​Right-click on the project nameSelect New >> FolderSet Folder name to i18nClick FinishRight-click on i18nSelect New >> OtherExpand Messages EditorSelect ResourceBundleClick NextSet the name to ReportsLocaleAdd a Locale (e.g., en_US)Click FinishAdd the i18n directory to the build process: Right-click i18nSelect Build Path >> Configure Build PathClick Add FolderCheck i18nClick OKClick OK againChange the createDateFormat method: @Override public DateFormat createDateFormat( String pattern, Locale locale, TimeZone timezone ) { String dateFormat = DATE_FORMAT_DEFAULT; try { ResourceBundle rb = ResourceBundle.getBundle( "ReportsBundle" ); String df = rb.getString( DATE_FORMAT ); if( df != null ) { dateFormat = df; } } catch( Exception e ) { // If the resource bundle isn't found, use the default date format. // TODO: Pass this exception into a logger. } return super.createDateFormat( dateFormat, locale, timezone ); }And add these constants to the class definition (immediately after the publc class declaration, around line 15/16): private final static String DATE_FORMAT = "date.format"; private final static String DATE_FORMAT_DEFAULT = "YYYY/MM/dd"; Restart Jaspersoft Studio, then: Edit the ReportsLocale fileAdd a date.format propertySet the property value to: dd/MM/YYYYSet the property value for all locales.When the report is run, the date should look like 29/02/1976, for example.
  10. BackgroundSometimes many reports and subreports must use the same default format (e.g., "YYYY/MM/dd") while only a handful of fields are an exception (e.g., "YYYY/MM"). QuestionWhat are the exact steps to ensure all date fields use the same date format, which can be changed in one location, without having to modify each field individually, such that individual fields can easily override the default? ResearchHere is a list of resources that fail to answer this question: http://community.jaspersoft.com/questions/543426/settign-default-format-factory-globally - no answerhttp://community.jaspersoft.com/questions/528989/decimal-formatting-rounding-mode-problem - suggests "sending an instance" of a DefaultFormatFactory subclass, but does not explain howhttp://stackoverflow.com/a/4018242/59087 - suggests setting a FormatFactory report property ("formatFactoryClass"), but does not explain howhttp://community.jaspersoft.com/wiki/how-show-pure-arabi%D1%81-numbers-report - provides an example DefaultFormatFactory subclass, but no answer shows how to use ithttp://community.jaspersoft.com/questions/539398/dont-get-custom-formatfactory-work-using-jrparameterreportformatfactory-parameter - shows a line of code that sets the REPORT_FORMAT_FACTORY parameter, but doesn't show how to get the reportParams instance, and also doesn't use Jaspersoft Studiohttp://community.jaspersoft.com/documentation/tibco-jaspersoft-studio-user-guide/v610/default-parameters - suggests that "the user can replace the default one" but doesn't mention how; also, refers to a "format factory class" property name, but doesn't indicate how to set it (from withint Jaspersoft Studio)http://www.dynamicreports.org/forum/viewtopic.php?f=1&t=250 - some code is given, but isn't a comprehensive examplehttp://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/JRParameter.html#REPORT_FORMAT_FACTORY - suggests using the "formatFactoryClass" attribute of the report template, but doesn't say how to set it (i.e., where to go within Jaspersoft Studio to change that particular attribute)http://www.spagoworld.org/jforum/posts/list/46.page - drops a "dateformat" in the REPORT_PARAMETERS_MAP, but doesn't indicate whether it is used globally, how it was set, etc.http://community.jaspersoft.com/questions/517926/date-field-timezone-locale-na - shows how to instantiate a custom DateFormatter, but must be applied on a field-by-field basisThe Definitive Guide seems to copy the Javadocs verbatim, which doesn't offer any additional insight. IdeasHere's how I thought it might be possible to set the formatFactoryClass attribute for a given report: Create a new ProjectOpen Project ExplorerRight-click on project nameSelect PropertiesExpand Jaspersoft StudioClick PropertiesClick Configure Workspace Settings buttonClick AddSet property name to any of: {net.sf.jasperreports.formatFactoryClass, or formatFactoryClass, or format.factory.class}Set value to (supply your own instance): com.package.reports.ReportFormatFactoryClick OK to close Properties DialogClick OK to close PreferencesClick OK to close Properties for ProjectThis would also require a Library that includes the com.package.reports.ReportFormatFactory class inside.
  11. Hi, Arun. See this answer: http://stackoverflow.com/a/5520421/59087 Paths must be absolute. Only compile .jrxml files to .jasper files if the .jrxml is being modified. Usually you can just load the .jasper file and skip compilation altogether. It is much faster. Store .jasper and .jrxml files outside of your web root. Create the following variables throughout all your reports: ROOT_DIR = "/full/path/to/reports/" IMAGE_DIR = $P{ROOT_DIR} + "images/" STYLES_DIR = $P{ROOT_DIR} + "styles/" SUBREPORT_DIR = $P{ROOT_DIR} + "subreports/" COMMON_DIR = $P{ROOT_DIR} + "common/" Reference items relative to $P{ROOT_DIR} (e.g., $P{IMAGE_DIR} is defined in terms of $P{ROOT_DIR}). Pass the value of $P{ROOT_DIR} in from your environment.-- Read chapter 15 of Indispensable, a book on JasperReports, available at: http://www.whitemagicsoftware.com/books/indispensable/
  12. Hi, Sandee. Visit http://whitemagicsoftware.com/books/indispensable/ Download the Software (v1.0.0) - it's free. Take a look at com/whitemagicsoftware/report/ReportImpl.javaSee also the attached file for a minimal example of how to create a PDF using JasperReports. You will have to supply your own .jasper file (compiled from a .jrxml file). This presumes a database connection to a local postgresql database is possible. You will have to change the database connectivity to match your database configuration and software. Read the JasperReports API to find out how to compile .jrxml files to .jasper files. -- Read chapter 15 of Indispensable, a book on JasperReports, available at: http://www.whitemagicsoftware.com/books/indispensable/
  13. Try: $F{TIPO_INCASSO}.equals("2") && $F{TIPO_1}.equals("C") ? Boolean.TRUE : Boolean.FALSE Or even: new Boolean( $F{TIPO_INCASSO}.equals("2") && $F{TIPO_1}.equals("C") ) -- Read chapter 15 of Indispensable, a book on JasperReports, available at: http://www.whitemagicsoftware.com/books/indispensable/ Post Edited by thangalin at 06/14/2011 11:22
  14. Use a session variable that tracks the user's credentials. -- Read chapter 15 of Indispensable, a book on JasperReports, available at: http://www.whitemagicsoftware.com/books/indispensable/
  15. Use the Report Integration Framework; it was designed with JSP and JSF integration in mind. http://www.whitemagicsoftware.com/software/java/rif/ -- Read chapter 15 of Indispensable, a book on JasperReports, available at: http://www.whitemagicsoftware.com/books/indispensable/
  16. You can use two lists (use java.util.List). The first list contains the names of the parameters. The second list contains the values of the parameters. See also the Report Integration Framework that illustrates how to pass these parameters generically. http://www.whitemagicsoftware.com/software/java/rif/ -- Read chapter 15 of Indispensable, a book on JasperReports, available at: http://www.whitemagicsoftware.com/books/indispensable/
  17. Use $X{ }: $X{IN, mycolumn,myList} http://blog.anorakgirl.co.uk/?p=29 -- Read chapter 15 of Indispensable, a book on JasperReports, available at: http://www.whitemagicsoftware.com/books/indispensable/
  18. Take a look at the Report Integration Framework. http://www.whitemagicsoftware.com/software/java/rif/ -- Read chapter 15 of Indispensable, a book on JasperReports, available at: http://www.whitemagicsoftware.com/books/indispensable/
  19. 1. Use a Text Field. 2. Drag the Text Field onto the Detail band. 3. Change the Text Field Expression to: java.lang.Math.pow( 20, 2.5 ) 4. Change the Expression Class to java.math.BigDecimal. -- Read chapter 15 of Indispensable, a book on JasperReports at: http://www.whitemagicsoftware.com/books/indispensable/
  20. The path to the image can be based on a parameter or variable. Allow the user to select a different logo and simply map the name of the logo to the path for the logo. So, if they select the "Jasper" logo, the parameter might point to "/home/reports/images/logos/jasper.png". All the images should be the same size and quality. http://www.whitemagicsoftware.com/
  21. Many JasperReports integrations based on JSP or JSF technology have two dangerous security flaws: Database connection credentials.Expose SQL statements.Database Connection Credentials Across various websites, I see answers to questions about JSP and JSF report integrations similar to the following: <%@ page import="java.sql.DriverManager"%><%String url = "jdbc:sqlserver://localhost:1433;DatabaseName=MIDAS10DB";Cnnection connection = DriverManager.getConnection(url, "username", "password" );[/code]Even though JasperReports needs a database connection, the user name and password must never be embedded in the JSP or JSF page itself. A mis-configuration of the web server, or a software bug, could accidentally expose key user names and passwords to anyone. Expose SQL Statements JasperReports uses compiled report templates (.jasper files) to generate the final report, such as a PDF. These templates contain SQL statements. If a malcious hacker were to guess the file name and download the file directly, it would expose a database attack vector. Quite often, SQL statements leverage database-specific features. By reading the SQL, a sufficiently knowledgeable hacker can make an educated guess on the database being used and possibly the database version. This can indirectly expose other information, such as the web server's operating system. (If the SQL uses Microsoft Access features, then chances are the operating system is Windows-based.) Most systems store the .jrxml and the .jasper files in the same directory as the JSP or JSF files, allowing them to be downloaded. Developers should avoid this situation. The Solution The solution for the second problem is easy: store the report template files outside of the web server's directory. The solution for the first problem is not simple. I have written a development framework that abstracts how the database connection is established. The implementation uses JNDI, but could equally leverage a different technology, without requiring any changes to the web application. http://www.whitemagicsoftware.com/software/java/rif/ http://www.whitemagicsoftware.com/software/java/rif/api/ Read Chapter 15 (available for free) of Indispensable to see how it works: http://www.whitemagicsoftware.com/books/indispensable/
  22. http://www.whitemagicsoftware.com/software/java/rif/ And http://www.whitemagicsoftware.com/books/indispensable/ (download and read chapter 15 for free) http://www.whitemagicsoftware.com/
  23. Ah, I thought you were using JasperReports, not JasperServer. The integration framework isn't so much a new technology as a layer of abstraction that simplifies integrating JasperReports with web development. (Essentially, people around the world are all hard-coding the same problems -- including some fairly severe security issues -- into their web applications; this API shields the web application from such tight coupling.) Post Edited by thangalin at 04/14/2011 19:51
  24. http://www.whitemagicsoftware.com/books/indispensable/ Download and read chapter 15. It shows how to use the Report Integration Framework in a JSP environment. http://www.whitemagicsoftware.com/
×
×
  • Create New...