Java Reference
In-Depth Information
package net.ensode.jasperbook;
import java.util.HashMap;
import java.util.Locale;
import net.sf.jasperreports.engine.JREmptyDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRParameter;
import net.sf.jasperreports.engine.JasperFillManager;
public class LocalizationDemoReportFill
{
public static void main(String[] args)
{
try
{
HashMap parameterMap = new HashMap();
if (args.length > 0)
{
parameterMap.put(JRParameter.REPORT_LOCALE, new
Locale(args[0]));
}
System.out.println("Filling report...");
JasperFillManager.fillReportToFile(
"reports/LocalizationDemoReport.jasper",
parameterMap, new JREmptyDataSource());
System.out.println("Done!");
}
catch (JRException e)
{
e.printStackTrace();
}
}
}
This example assumes we have already created a Jasper template from the JRXML
template. If no command-line parameters are sent to the preceding code, it will use
the default locale; otherwise, it will use the first command-line parameter as the
locale. If we pass the String es as the first command-line parameter, the report will
be generated in Spanish. The generated report will look like this:
 
Search WWH ::




Custom Search