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 8841345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:41:32+00:00 2026-06-14T10:41:32+00:00

Im used JSF and PrimeFaces. I have an ActionListener that fires when someone clicks

  • 0

Im used JSF and PrimeFaces. I have an ActionListener that fires when someone clicks on a MenuItem:

@Override
public void processAction(ActionEvent event) throws AbortProcessingException
{
    Resource resouce = getResources().get(0);
    try
    {
        ResourceDelegate delegate = new ResourceDelegate(resouce, configDao);
        JSFUtils.writeToOutputStream(Mime.getMimeTypeForFileType(FileUtilities.getExtension(resouce.getName())), delegate.getData());
    }
    catch(Exception e)
    {
        logger.log(Level.SEVERE, "Cant show resource",e);
    }

}

In that menu item, I write the data of an image to the request stream using the following code:

/**
 * Writes binary data to the response for the browser to display
 * @param contentType
 * @param data
 * @throws IOException 
 */
public static void writeToOutputStream(String contentType, byte[] data) throws IOException
{
    FacesContext context = FacesContext.getCurrentInstance();
    HttpServletResponse hsr = getHttpServletResponse();
    hsr.setContentType(contentType);
    OutputStream stream = hsr.getOutputStream();
    stream.write(data);
    //Tell JSF to skip the remaining phases of the lifecycle
    context.responseComplete();
}

When the ActionListener is done, I expect that the image would be displayed, however, this is not the case. Nothing happens. Is there something else I need to do to get the image to display correctly?

  • 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-14T10:41:34+00:00Added an answer on June 14, 2026 at 10:41 am

    That can happen if the request is been fired by ajax, which is by default the case in almost all PrimeFaces action components. In case of JSF/PrimeFaces, ajax requests are supposed to return a special XML response which contains among others information about which parts of the HTML DOM are to be updated and how.

    You’re here however sending a "file download" as ajax response. This can’t be interpreted as such by PrimeFaces’ ajax engine. Also, JavaScript has due to security reasons no facilities to force a Save As dialogue. It should really be requested by a synchronous request.

    In case of the PrimeFaces <p:menuitem>, you’d need to add the ajax="false" attribute to turn off the ajax nature and let it fire a synchronous request instead.

    <p:menuitem ... ajax="false" />
    

    (same attribute is also available on all other action components of PrimeFaces such as <p:commandButton>)

    That "nothing happens" is actually not true. You’d have seen the concrete HTTP response in the "Network" section of webbrowser’s builtin webdeveloper’s toolset (press F12 in Chrome/IE9/Firebug). You should probably even have a JavaScript error in the JavaScript console about an uninterpretable ajax response.

    See also:

    • How to provide a file download from a JSF backing bean?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this Java code which is used for JSF pagination: public List<ActiveSessionObj> list(int
I have implemented a login form using JSF and PrimeFaces. I used this example
I have a JSF 1.2 application (Sun RI, Facelets, Richfaces) that was used only
I read somewhere the view ids used by JSF framework have a happy side
I have this JSF table which is used to display data. I want to
I have a JSF page that displays a table from an object called TableQuery
i am using jsf 2.1.1 and primefaces 3.0.M4. i have a sample jsf page
Can someone who is an active JSF (or Primefaces) user explain why by default
I have a problem using JSF 2.0, PrimeFaces and the tuckey.org UrlRewriteFilter. The problem
I used primefaces showcase example, http://www.primefaces.org/showcase/ui/layoutElement.jsf but it is not displaying anything. My 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.