5 Replies Latest reply on Dec 20, 2007 2:32 PM by balteo

    Using a a4j:commandButton in order to download a text file.

    balteo

      Hello,

      I use a h:commandButton in order to download an application-generated text file as follows:

      The h:commandButton's action atttribute is wired to the following method:

       public String exportDeclaration() {
       log.debug("exportDeclaration");
       FacesContext facesContext = FacesContext.getCurrentInstance();
       if (!facesContext.getResponseComplete()) {
       String fileName = "export.wri";
      
       ServletContext servletContext = (ServletContext) facesContext.getExternalContext().getContext();
       String contentType = servletContext.getMimeType(fileName);
      
       HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
       response.setContentType(contentType);
       response.setHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\"");
      
      
       StatementDirector director = new StatementDirector();
       StatementBuilder builder = new StatementMacroBuilder(remissionNumber);
       director.setStatementBuilder(builder);
       director.constructStatement();
       StatementContainer statement = director.getStatement();
       try {
       PrintWriter writer = response.getWriter();
       writer = StatementGenerator.generate(statement, writer);
       writer.flush();
       facesContext.responseComplete();
       } catch (FileNotFoundException ex) {
       ex.printStackTrace();
       } catch (IOException ex) {
       ex.printStackTrace();
       }
       }
       return null;
       }
      


      Do you see any way of using a a4j:commandButton instead? Which would allow me to use a a4j:status component??

      Any clue welcome,

      Julien.