![](/img/trans.png)
[英]java.util.GregorianCalendar issue with add() when applying DST changes
[英]JasperReports Server: Getting “java.util.GregorianCalendar not configured” error when using java.util.Calendar at scriptlet
我使用iReport设计报告。 在此报告中,我有一个自定义函数,该函数将年和月作为输入并返回该月的最大天数。
此方法在内部使用java.util.Calendar API来获取给定月份和年份中的最大天数。
该报告可与iReport配合使用,但是一旦我在JasperReports Server中导入此报告,我就会收到此异常。
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的数据转换器配置,但是没有此类数据转换器可用于Calendar类。
最好的方法是创建自定义类,在其中编写要使用java Calendar类执行的整个逻辑并将其打包到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,以从输入中获得所需的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.