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.
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.
An IDE is no substitute for an Intelligent Developer.
Joined: Feb 13, 2010
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.
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.
Joined: Feb 13, 2010
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.