Report html view with error

Hello everyone
I have the following scenario.
An application that attends shifts through windows generates a summary of the shift that is displayed in an html view.
On occasions when the application is being used on different computers and with different users and simultaneously the report of the attended turn is issued, this report is presented changed, that is, window A presents turn 1B and window B presents turn 1A, when the correct thing would be for the window to present turn 1A and the window to present turn 1B.
At the backend level, the information stored in the database is correctly registered.

And when the shift report is exported in pdf or word format, they show the data exchanged.

I attached a part of the code

   public String getHTML(Integer pagina) throws ServiceException {
      String res = null;
      if (pagina == 0) {
         return res;
      }
      if (jasperPrint != null && jasperPrint.getPages() != null && !jasperPrint.getPages().isEmpty()) {
         try {
            Exporter exporter = new HtmlExporter(DefaultJasperReportsContext.getInstance());
            LOGGER.error("Exporter: " + exporter.toString());
            SimpleExporterInput exporterInput = new SimpleExporterInput(jasperPrint);
            exporter.setExporterInput(exporterInput);
            try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
               SimpleHtmlExporterOutput simpleHtmlExporterOutput = new SimpleHtmlExporterOutput(out);
               HtmlResourceHandler imageHandler = new HtmlResourceHandler() {
                  @Override
                  public void handleResource(String id, byte[] data) {
                     images.put(id, "data:image/jpg;base64," + Base64.encodeBytes(data));
                  }

                  @Override
                  public String getResourcePath(String id) {
                     return images.get(id);
                  }
               };
               simpleHtmlExporterOutput.setImageHandler(imageHandler);
               exporter.setExporterOutput(simpleHtmlExporterOutput);
               exporter.exportReport();
               res = new String(out.toByteArray(), StandardCharsets.UTF_8);
               out.flush();
            }
         } catch (JRException | IOException ex) {
            LOGGER.error(ERROR_GENERANDO_HTML_REPORTE + ex.getMessage(), ex);
            throw new ServiceException(ERROR_GENERANDO_HTML_REPORTE + ex.getMessage(), ex);
         }
      }
      return res;
   }

Maybe you have some recommendation or some change in the code that should be done?

carlostrujillo.a's picture
Joined: Feb 22 2023 - 12:43pm
Last seen: 5 months 3 weeks ago

Thank you for posting to the Jaspersoft Community. Our team of experts has read your question and we are working to get you an answer as quickly as we can. If you have a Jaspersoft Professional Subscription plan, please visit https://support.tibco.com/s/ for direct access to our technical support teams offering guaranteed response times.

mrajkuma - 5 months 3 weeks ago

Hi,

This seems like some synchronization issue with the code, can you debug with breakpoints and see if retrieving jr print is being mixed up. It looks like the jr print object is not synchronized or is not correctly updated.

mbamania - 5 months 2 weeks ago

0 Answers:

No answers yet
Feedback