This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
My first post here but I can see myself frequenting as I battle with JSF!
I have a page whereby people search for reports and the results are returned to them in a datatable. They are first faced with some input input controls to refine their search, they click search and control goes to a session backing bean. The backing bean gets the records from the database, populates a list, sets a boolean value to true and then reloads the page. The boolean value causes a previously non-rendered datatable to be displayed. Each row will have contain a picture of a PDF. Upon clicking this PDF, the user should be given a download prompt and be able to download the corresponding PDF.
This all works fine, however after the PDF has been downloaded, I cannot continue to use the page and must navigate to a different page and then return. If I use other controls within the same form, I get the download prompt again for the same file, as well as an exception thrown:
Here is the code I am using to return the PDF through the response:
The PDF pictures which prompt the download when clicked are surrounded by a command link which has an action listener which sets PDFArchiveChosen. The action for the link is the method shown above, which streams the PDF to the user.
What I want is for users to click on a PDF picture and download the corresponding file. Once they've done that, I want them to be able to use the page as normal: run different searches, click other pdf pictures to get different files downloaded etc.
Ekrem Dkyc wrote:Hello, did you try using a normal <h:link> ?
Hi Ekrem, thanks for the reply.
At first I thought this wouldn't help as <h:link> (I only had <hutputLink> available), does not have action, actionListener attributes so I wouldn't be able to link it with the backing bean in order to set the report chosen and then pull the PDF from the Database and then stream it back to the user. I thought I'd give it a go though.
I didn't think this would work as it is still using a commandButton with an action event to initiate streaming. It seems to work great though! I'm not sure why - the difference seems to be that I'm not using an actionListener and that the link clicked is outside the Datatable - which I suspect is the main offender.