我有使用iReport的设计报告。在此报告中,我有一个自定义函数,该函数将年份和月份作为输入并返回该月的最大天数。
此方法在内部使用 java.util.Calendar API 来获取给定月份和年份的最大天数。
此报告适用于 iReport,但是一旦我在 JasperReports 服务器中导入此报告,我就会收到此异常。
Error Message
java.lang.IllegalStateException: Processor of type com.jaspersoft.jasperserver.war.cascade.handlers.converters.DataConverter for class
java.util.GregorianCalendar not configured
如何在JasperReports Server中解决此问题?如何在JasperReports Server中配置此类?
在研究了上述问题之后,我自己设法解决了它。我已经研究了JasperServer的数据转换器配置,但没有可用于日历类的数据转换器。
我发现最好的方法是创建自定义类,在其中编写要使用 java 日历类执行的整个逻辑并将其打包到 jar 中。现在直接使用该jar API来解决您的目的。
就我而言,我想计算报告期(我生成报告的时间段)。对我来说,这个结果的输入是我生成报告的月份和年份。所以下面是我写的代码片段
public static String calculateReportingPeriod(String year, String month,
String dateFormat) {
String reportingPeriod = new String();
Calendar calendar = Calendar.getInstance();
if (year == null || year.isEmpty()) {
Integer lyear = Calendar.getInstance().get(Calendar.YEAR);
year = lyear.toString();
}
if (month == null || month.isEmpty()) {
Integer lmonth = Calendar.getInstance().get(Calendar.MONTH);
/**
* -1 because report in generate for previous month
*/
lmonth = lmonth - 1;
month = lmonth.toString();
} else {
Integer lmonth = Integer.parseInt(month);
lmonth = lmonth - 1;
month = lmonth.toString();
}
if (dateFormat == null || dateFormat.isEmpty()) {
dateFormat = DATE_FORMAT;
}
/**
* calculating max days in the given month and given year
*/
calendar.set(Calendar.YEAR, Integer.parseInt(year));
calendar.set(Calendar.MONTH, Integer.parseInt(month));
Integer maxDays = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
calendar.set(Integer.parseInt(year), Integer.parseInt(month),
START_DATE);
Date reportingStartDt = calendar.getTime();
reportingPeriod = new SimpleDateFormat(dateFormat)
.format(reportingStartDt);
reportingPeriod = reportingPeriod.concat(EMPTY_STRING);
reportingPeriod = reportingPeriod.concat(DASH_SEPERATOR);
reportingPeriod = reportingPeriod.concat(EMPTY_STRING);
calendar.set(Calendar.DATE, maxDays);
Date reportingEndDt = calendar.getTime();
reportingPeriod = reportingPeriod.concat(new SimpleDateFormat(
dateFormat).format(reportingEndDt));
return reportingPeriod;
}
然后,我在iReports和JasperServer中使用了这个jar,以从输入中获得所需的结果。