• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSF page won't reload if I write to ByteArrayOutputStream

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Basically, I have a JSF page that displays a count and a "download" button. What I want to have happen is when the button is clicked a text file is created and downloaded and the page's count gets incremented.

When I click the CommandButton the bean.download method gets called, text gets written to a ByteArrayOutputStream and is downloaded. But the count does not refresh (page isn't reloaded).

If I don't call the method to write to the ByteArrayOutputStream, then the page does get updated and shows the new count value.

The JSF page:




The Session bean: Bean




Thanks for any help.
 
Saloon Keeper
Posts: 27807
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Stephen!

JSF is designed to facilitate HTML data, and especially pages with forms on them. The parts of your webapp that need to output non-HTML data should be implemented in the traditional way using servlets or JSPs. JSF does not require that every part of a webapp must be done exclusively with JSF and the JSF and non-JSF parts of a webapp can freely communicate with each other because the JSF scopes and J2EE scopes are actually the same things, making a JSF session object accessible via the J2EE session API, for example.
 
stephen wills
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tim,
Thanks for your reply. I'm still a bit unclear of how else I can approach this. I need the JSF button to initiate the download which results in the server returning a file to download. But I also need to show on the web page that the download count has been updated which doesn't happen if the server returns a file. I guess I don't understand what you are telling me. Further advice would sure be welcome.
Cheers
 
Tim Holloway
Saloon Keeper
Posts: 27807
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your download button needs to reference a non-JSF URL (use the h:outputLink tag). That URL should run the Excel file generator that returns the spreadsheet to be downloaded.

Because this kind of operation doesn't navigate away from the JSF screen, you can then use AJAX to update the backing bean containing the download count and re-render the count in the current page display.
 
stephen wills
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your help Tim. I got around the problem by adding to the commandButton to reload the page after one second. Not the best solution but it works.
Cheers
Stephen
 
Tim Holloway
Saloon Keeper
Posts: 27807
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's basically what AJAX does, except that it only updates the part of the page that actually changes instead of the whole thing.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic