Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8865409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:30:04+00:00 2026-06-14T16:30:04+00:00

everyone! I have a trouble. I tried to save excel file in jsf web

  • 0

everyone!

I have a trouble. I tried to save excel file in jsf web application.
I generated file by my utils and trying to get “save” window, but I failed.

Here is my code:

  <div>
  <h:commandButton value="Apply" actionListener="#{hornPhonesBean.generateReport}"/>
  </div>

and:

   public void generateReport(ActionEvent event) {
    System.out.println("GENERATE REPORT FROM = " + this.dateFrom + "; TO = " + this.dateTo);

    try {
        XSSFWorkbook workbook = (XSSFWorkbook) HornReportGenerator.getWorkbook(null, null);
        String fileName = "1.xlsx";

        FacesContext fc = FacesContext.getCurrentInstance();
        ExternalContext ec = fc.getExternalContext();

        // Some JSF component library or some Filter might have set some headers in the buffer beforehand. We want to get rid of them, else it may collide.
        ec.responseReset(); 

        // Check http://www.w3schools.com/media/media_mimeref.asp for all types. Use if necessary ExternalContext#getMimeType() for auto-detection based on filename.
        ec.setResponseContentType("application/vnd.ms-excel"); 

        // Set it with the file size. This header is optional. It will work if it's omitted, but the download progress will be unknown.
        //ec.setResponseContentLength(contentLength); 

        // The Save As popup magic is done here. You can give it any file name you want, this only won't work in MSIE, it will use current request URL as file name instead.
        ec.setResponseHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\""); 

        OutputStream output = ec.getResponseOutputStream();
        workbook.write(output); 
        output.flush();
        output.close();

        fc.responseComplete(); // Important! Otherwise JSF will attempt to render the response which obviously will fail since it's already written with a file and closed.
        System.out.println("END");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

I read suggestions here and from another forums – everyone says I shouldnt use , but I didn’t use it at all.

Then I thought that the problem could be in the

 <ice:form>, 

where I kept the

 <h:commandButton>, 

and I changed to

 <h:form>, 

but it didn’t help.

Maybe the problem in the request – it has header Faces-Request partial/ajax. But I am not sure.

Please give me some ideas – I already spent 4 hours for this crazy jsf download issue)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T16:30:05+00:00Added an answer on June 14, 2026 at 4:30 pm

    Maybe the problem in the request – it has header Faces-Request partial/ajax. But I am not sure.

    This suggests that the request is an ajax request. You can’t download files by ajax. Ajax requests are processed by JavaScript which has for obvious security reasons no facilities to programmatically pop a Save As dialogue nor to access/manipulate client’s disk file system.

    Your code snippet does however not show that you’re using ajax. Perhaps you oversimplified it too much or you’re using ICEfaces which silently auto-enables ajax on all standard JSF command components.

    In any case, you need to make sure that it’s not sending an ajax request.

    See also:

    • How to provide a file download from a JSF backing bean?
    • ICEfaces libary in classpath prevents Save As dialog from popping up on file download
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello everyone Masters Of Web Delevopment :) I have a piece of PHP script
everyone. I have some labels that I draw them in the xib file, and
I have trouble sending a message via NServiceBus. I have an ASP.Net MVC web
Hey everyone! I am having trouble with understanding modules -- I have two files,
Hello everyone: I am trying to get a data pull from MySQL within a
I have canvas FBML app for facebook in Java. I am trying to get
Hello everyone I have a problem. I want to do a GridView with a
Have a nice day everyone, I have something to ask your hel, to better
I have a central git repository that everyone pushes to for testing and integration,
everyone! I have sprite moving by action, what have health bar (progress bar). When

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.