[英]JasperReports Server: Getting “java.util.GregorianCalendar not configured” error when using java.util.Calendar at scriptlet
I have design report using iReport . 我使用iReport设计报告。 In this report I have one custom function which takes year and the month as input and return max days in that month.
在此报告中,我有一个自定义函数,该函数将年和月作为输入并返回该月的最大天数。
This method using java.util.Calendar API internally to get max days in the given month and year. 此方法在内部使用java.util.Calendar API来获取给定月份和年份中的最大天数。
This reports works fine with iReport , but as soon as I import this report in JasperReports Server I am getting this exception. 该报告可与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
How to resolve this issue in JasperReports Server ? 如何在JasperReports Server中解决此问题? How to configure this class in JasperReports Server ?
如何在JasperReports Server中配置此类?
After researching for above problem, I myself manage to work it out. 经过研究上述问题,我自己设法解决了。 I have looked into the data converters configuration of JasperServer but there is no as such Data converter available for Calendar class.
我已经研究了JasperServer的数据转换器配置,但是没有此类数据转换器可用于Calendar类。
To best way I have found is that to create you custom class in which write your whole logic that you want to perform with java Calendar class and package it into jar. 最好的方法是创建自定义类,在其中编写要使用java Calendar类执行的整个逻辑并将其打包到jar中。 Now use use that jar API directly to solve you purpose.
现在直接使用该jar API即可解决您的目的。
In my case I wanted to calculate the reporting period (Time period for which I am generating report). 就我而言,我想计算报告时间段(我生成报告的时间段)。 For me the input for this result was month and the year for which I am generating the reports.
对我来说,此结果的输入是我生成报告的月份和年份。 So below is my code snippet I have written
所以下面是我写的代码片段
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;
}
Then I have used this jar in both iReports as well as in JasperServer to get the desired result from the input. 然后,我在iReports和JasperServer中都使用了此jar,以从输入中获得所需的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.