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

  • SEARCH
  • Home
  • 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 3438484
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:11:36+00:00 2026-05-18T08:11:36+00:00

Using a commandButton in a jsf Page to download a file. Using: JSF &

  • 0

Using a commandButton in a jsf Page to download a file. Using: JSF & Richfaces.

I have a table (extends ExtendedDataModel implements Modifiable, Serializable) with some data and in each row a button “download”.

<a4j:commandButton id="getDownload" value="download" 
    style="margin-left:10px;margin-right:10px;width:100px;"
    action="#{controller.download}" immediate="true" ajaxSingle="true">
    <f:setPropertyActionListener target="#{controller.idString}" value="#{item.id}" />                     
</a4j:commandButton>

I have to build the file in the controller:

public void download(){
 OutputStream out = null;
....

FacesContext fc = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) fc.getExternalContext().getResponse();
out = response.getOutputStream();

ZipOutputStream zipout = new ZipOutputStream(out);
.....

zipout.close();
response.setContentType("application/octet-stream");
response.addHeader("Content-Disposition", "attachment; filename=\""+filename+"\"");
out.flush();
....

} finally {
    try {
        if (out!=null){
            out.close();
        }
        FacesContext.getCurrentInstance().responseComplete();
    } catch (IOException e) {
        logger.error(e);
    }

}
...
}

The Problem started, when I implemented the ExtendedDataModel my self.
At first i used h:commandLink, but the controller method was never called… i tried and tried… now the correct method is called, but the (zip) file content is displayed in the page. I want a button/link in the page, which the user can click to download the file. The page itself should not change. Any ideas?

I can create a servlet, but i do not understand why the ExtendedDataModel changed the behavior of the links inside.

Edit1

I used

<h:commandLink id="getDownload" value="download" action="#{controller.download}">                                                       
                            <f:setPropertyActionListener target="#{controller.idString}" value="#{item.id}" />                              
                        </h:commandLink>

before. It works with the “normal” richfaces table, but not when i used it inside my own table which extends ExtendedDataModel.

Edit 2 – Solution/Workaround

It is impossible to use the h:commandButton, .. Link… whatever inside of the self made table, to download a file. I am now using one button in the table to render a new PanelGroup and a second button inside of the new PanelGroupt to download the file.
I googled a lot for this, seems like a rich faces bug.

  • 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-05-18T08:11:36+00:00Added an answer on May 18, 2026 at 8:11 am

    You can’t download a file by ajax request. Replace a4j:commandButton by h:commandButton.


    Update as per your question update: to get command links/buttons inside an UIData component such as <h:dataTable>, <rich:dataTable>, etc to work, you need to ensure that the bean which is holding the data model (whatever is behind the value attribute of the UIData component) is preserving exactly the same data model during the request of the form submit. If you want to keep your bean request scoped, then the easiest way is to reference the bean in an <a4j:keepAlive> tag.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using jsf 1.2, hibernate, richfaces 3.3.0GA and facelets. I have this code in my
In my JSF 1.2 webapp I have a page with a <h:commandButton> that invokes
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
I'm using JSF (Mojarra 1.2) with Richfaces (3.3.2) within some facelets which are used
I have a JSF Page which gets few inputs from the User, I want
I have JSF page has two drop down lists and I want to load
I am trying to implement a scenario using JSF. I have a commandExButton and
I want to render 6 blocks on a page asynchronously using richfaces a4j support.
I have a JSF page that is basically a create form. The form consists
Hi im studying JSF 2.0 Using tomcat 6.0.26 When a start a simple page

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.