thangalin
-
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
Posts posted by thangalin
-
-
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:
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:
The single text field is created.
Preview Report
For a report with three pages plus a summary page, previewing the report shows:
The summary page shows:
- Create a variable called `V_CURRENT_PAGE_NUMBER`
-
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.xml
- Set 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).
-
What are the steps to create a distribution library that contains all the:
- Report images
- Internationalized resource bundles
- Class files (for custom functionality)
- Report templates
-
-
-
-
-
The following seems to work:
- Click Window >> Prefereces
- Select Capabilities
- Check Development
- Click OK
Next:
- Open the Project Explorer
- Right-click Project name
- Select Properties
- Select Java Build Path
- Click the Source tab
- Click Add Folder
- Select Create New Folder
- Set Folder Name to: src
- Click Finish
- Select src
- Click OK
- Set Default output folder: Project Name/build
- Click OK
Create 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 panel
- Open the Properties panel
- Set Format Factory Class to: com.company.reports.ReportFormatFactory
Next, 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.*/@Overridepublic 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 name
- Select New >> Folder
- Set Folder name to i18n
- Click Finish
- Right-click on i18n
- Select New >> Other
- Expand Messages Editor
- Select ResourceBundle
- Click Next
- Set the name to ReportsLocale
- Add a Locale (e.g., en_US)
- Click Finish
Add the i18n directory to the build process:
- Right-click i18n
- Select Build Path >> Configure Build Path
- Click Add Folder
- Check i18n
- Click OK
- Click OK again
Change the createDateFormat method:
@Overridepublic 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 file
- Add a date.format property
- Set the property value to: dd/MM/YYYY
- Set the property value for all locales.
When the report is run, the date should look like 29/02/1976, for example.
-
Background
Sometimes 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").
Question
What 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?
Research
Here is a list of resources that fail to answer this question:
- http://community.jaspersoft.com/questions/543426/settign-default-format-factory-globally - no answer
- http://community.jaspersoft.com/questions/528989/decimal-formatting-rounding-mode-problem - suggests "sending an instance" of a DefaultFormatFactory subclass, but does not explain how
- http://stackoverflow.com/a/4018242/59087 - suggests setting a FormatFactory report property ("formatFactoryClass"), but does not explain how
- http://community.jaspersoft.com/wiki/how-show-pure-arabi%D1%81-numbers-report - provides an example DefaultFormatFactory subclass, but no answer shows how to use it
- http://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 Studio
- http://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 example
- http://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 basis
The Definitive Guide seems to copy the Javadocs verbatim, which doesn't offer any additional insight.
Ideas
Here's how I thought it might be possible to set the formatFactoryClass attribute for a given report:
- Create a new Project
- Open Project Explorer
- Right-click on project name
- Select Properties
- Expand Jaspersoft Studio
- Click Properties
- Click Configure Workspace Settings button
- Click Add
- Set 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.ReportFormatFactory
- Click OK to close Properties Dialog
- Click OK to close Preferences
- Click OK to close Properties for Project
This would also require a Library that includes the com.package.reports.ReportFormatFactory class inside.
-
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/ -
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.java
See 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/ -
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 -
Use a session variable that tracks the user's credentials.
--
Read chapter 15 of Indispensable, a book on JasperReports, available at:
-
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:
-
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:
-
Use $X{ }: $X{IN, mycolumn,myList}
http://blog.anorakgirl.co.uk/?p=29
--
Read chapter 15 of Indispensable, a book on JasperReports, available at:
-
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:
-
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:
-
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.
-
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/
-
http://www.whitemagicsoftware.com/software/java/rif/
And
http://www.whitemagicsoftware.com/books/indispensable/ (download and read chapter 15 for free)
-
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 -
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/software/java/rif/
http://www.whitemagicsoftware.com/software/java/rif/api/com/whitemagicsoftware/report/Parameters.html#PARAM_REPORT_FILENAMEThe idea is that you make the file name part of a parameter that is filled in by the HTTP FORM POST action.
If you need to include a programmatic item (such as the date), you override a single method to provide the appropriate value.
If you have questions, let me know.
Post Edited by thangalin at 04/13/2011 23:47
Page X of Y -- How to display it right aligned and neatly formatted without spaces
in Products
Posted
See: http://stackoverflow.com/a/37552266/59087