ICEfaces
  1. ICEfaces
  2. ICE-7226

ACE exporters use servlet specific APIs

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.2
    • Fix Version/s: 2.1-Beta, 3.0
    • Component/s: ACE-Components
    • Labels:
      None
    • Environment:
      ICEfaces 2 ACE exporters portlets
    • Assignee Priority:
      P1

      Description

      In order to support running in a portlet, it's imperative the core, component, and application related code use standard JSF APIs whenever possible and avoid any casting to classes or using methods that are not agnostic to the environment they are running in.

      In the various ACE exporter classes (CSVExporter, PDFExporter, XMLExporter, ExcelExporter) we have code that looks like this (from CSVExporter.export):

      ...
      HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
      OutputStream os = response.getOutputStream();
      OutputStreamWriter osw = new OutputStreamWriter(os , encodingType);
      PrintWriter writer = new PrintWriter(osw);
      ...
           response.setContentType("text/csv");
           response.setHeader("Expires", "0");
              response.setHeader("Cache-Control","must-revalidate, post-check=0, pre-check=0");
              response.setHeader("Pragma", "public");
              response.setHeader("Content-disposition", "attachment;filename="+ filename + ".csv");
              
              writer.flush();
              writer.close();
              
              response.getOutputStream().flush();
      }

      Casting to HttpServletResponse causes a problem when running in a portlet. The JSF way to do this which avoids the casting exception with portlets:

      ...
              ExternalContext ec = facesContext.getExternalContext();
      OutputStream os = ec.getResponseOutputStream();
      OutputStreamWriter osw = new OutputStreamWriter(os , encodingType);
      PrintWriter writer = new PrintWriter(osw);
      ...
           ec.setResponseContentType("text/csv");
           ec.setResponseHeader("Expires", "0");
              ec.setResponseHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
              ec.setResponseHeader("Pragma", "public");
              ec.setResponseHeader("Content-disposition", "attachment;filename=" + filename + ".csv");
              
              writer.flush();
              writer.close();
              
              os.flush();
      }

      All of the current exporters I noted need to have this corrected. Perhaps some common code could be lifted up to the parent abstract Exporter class.

        Issue Links

          Activity

            People

            • Assignee:
              yip.ng
              Reporter:
              Deryk Sinotte
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: