tried setting REPORT_TIME_ZONE four ways to no avail

0

 

In the following code, I have tried in vain to set the REPORT_TIME_ZONE according to what I have able to glean from reading all the discussion in these forums.  The result is the same, the JVM time zone is picked up instead of the timezone I am passing in "US/Pacific".

    public void writeCSVReport(Writer writer, ReportResultsDto resultDto)
            throws IOException, ClassNotFoundException, JRException {
           
        TimeZone timezone = resultDto.getTimezone();

        FastReportBuilder reportBuilder = new FastReportBuilder();
        reportBuilder.setUseFullPageWidth(false);
        reportBuilder.setPrintColumnNames(true);
        reportBuilder.setIgnorePagination(true);
        reportBuilder.setProperty(JRParameter.REPORT_TIME_ZONE, timezone.getID());

        int index = 0;
        for (ReportColumnMetadataDto metadataDto : resultDto.getMetadata()) {
            if (metadataDto.isDisplay()) {
                String columnLabel = metadataDto.getLabel();
                String columnClassName = metadataDto.getColumnClass();
                ClasscolumnClass = Class.forName(columnClassName);
                
                System.out.println("index="+index+"    label="+columnLabel+"     className="+columnClassName);
                
                if (java.util.Date.class.isAssignableFrom(columnClass)) {
                    reportBuilder.addColumn(columnLabel, String.valueOf(index),
                        columnClassName, metadataDto.getColumnSize(), false, "MM/dd/yyyy hh:mm:ss a zzz");
                } else {
                    reportBuilder.addColumn(columnLabel, String.valueOf(index),
                        columnClassName, metadataDto.getColumnSize());
                }
            }
            index++;  
        }

        DynamicReport dynamicReport = reportBuilder.build();
        dynamicReport.setProperty(JRParameter.REPORT_TIME_ZONE, timezone.getID());
        
        JRDataSource dataSource = new ReportResultsJRDataSource(resultDto);
        ((JRAbstractTextDataSource)dataSource).setTimeZone(timezone.getID());
        
        JasperPrint jasperPrint = DynamicJasperHelper.generateJasperPrint(dynamicReport, new ListLayoutManager(), dataSource);
        jasperPrint.setTimeZoneId(timezone.getID());
        
        System.out.println("\n TIME ZONE SET TO >>>"+jasperPrint.getTimeZoneId()+"\n");

        JRCsvExporter exporter = new JRCsvExporter();
        exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
        exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, writer);
        exporter.exportReport();

        writer.flush();
    }

 

 

Here is the output ...

 

index=0    label=My First Name     className=java.lang.String
index=1    label=My Last Name     className=java.lang.String
index=2    label=Email Address     className=java.lang.String
index=13    label=Registration Date     className=java.sql.Timestamp
index=14    label=Registration Status     className=java.lang.String
index=15    label=Payment Status     className=java.lang.String
index=16    label=Payment Type     className=java.lang.String

 TIME ZONE SET TO >>>US/Pacific

My First Name,My Last Name,Email Address,Registration Date,Registration Status,Payment Status,Payment Type
John,Doe,johndoe@yahoo.com,12/07/2012 04:03:52 PM EST,Registered,Not Applicable,

 

Any idea how I get jasper or dynamic jasper to respect the time zone?

 

Thanks in advance.

 

jesimone57's picture
Joined: Dec 7 2012 - 1:10pm
Last seen: 8 years 11 months ago

1 Answer:

0

Here is the solution.   We needed to get the jasperPrint object to respect the timezone.  Unforunately, setting the timezone id into the jasper print object does not do anything.   I removed all the red code from the above post, which did not do anything either.

 

   public void writeCSVReport(Writer writer, ReportResultsDto resultDto)
            throws IOException, ClassNotFoundException, JRException {
           
        TimeZone timezone = resultDto.getTimezone();

        FastReportBuilder reportBuilder = new FastReportBuilder();
        reportBuilder.setUseFullPageWidth(false);
        reportBuilder.setPrintColumnNames(true);
        reportBuilder.setIgnorePagination(true);

        int index = 0;
        for (ReportColumnMetadataDto metadataDto : resultDto.getMetadata()) {
            if (metadataDto.isDisplay()) {
                String columnLabel = metadataDto.getLabel();
                String columnClassName = metadataDto.getColumnClass();
                ClasscolumnClass = Class.forName(columnClassName);
                
                System.out.println("index="+index+"    label="+columnLabel+"     className="+columnClassName);
                
                if (java.util.Date.class.isAssignableFrom(columnClass)) {
                    reportBuilder.addColumn(columnLabel, String.valueOf(index),
                        columnClassName, metadataDto.getColumnSize(), false, "MM/dd/yyyy hh:mm:ss a zzz");
                } else {
                    reportBuilder.addColumn(columnLabel, String.valueOf(index),
                        columnClassName, metadataDto.getColumnSize());
                }
            }
            index++;  
        }

        DynamicReport dynamicReport = reportBuilder.build();
        
        JRDataSource dataSource = new ReportResultsJRDataSource(resultDto);
  

            Map paramMap = new HashMap();
            paramMap.put(JRParameter.REPORT_TIME_ZONE, timezone);
,>
,>

            JasperPrint  jasperPrint = DynamicJasperHelper.generateJasperPrint(dynamicReport, new ListLayoutManager(),

                     dataSource, paramMap);
    
        System.out.println("\n TIME ZONE SET TO >>>"+jasperPrint.getTimeZoneId()+"\n");

        JRCsvExporter exporter = new JRCsvExporter();
        exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
        exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, writer);
        exporter.exportReport();

        writer.flush();
    }

 

 

jesimone57's picture
Joined: Dec 7 2012 - 1:10pm
Last seen: 8 years 11 months ago
Feedback