I need to show a link to download a file on a page in a JSF 2 application. Now, the issue is that the file contains data that depends on fresh looks into the database at the time of creation. But what I want to do is create it AND give the user a link to download it in one action.
This would be very simple to do in two actions: have a button to generate the file, and replace it with a link to download the file once it's generated.
So the question again is can this be done in one click on a commandLink?
EDIT, following BalusC's comment below. Here's the specifics of what I am trying to do, and have done so far. I have this in the xhtml:
<h:panelGroup rendered="#{!bean.showLinkToExcelFile()}">
<h:form>
<td><h:commandButton value="Generate list of your Bids for download" action="#{bean.createBidsList()}"/></td>
</h:form>
</h:panelGroup>
<h:panelGroup rendered="#{bean.showLinkToExcelFile()}">
<td><a href="#{bean.findBidsListFileName()}">Download Your Bids</a></td>
</h:panelGroup>
This works. The button creates an excel file, saves it to a location, and updates the file name in the database. Then the link serves the file. But it's a two step process for the user. What I'd like it to be is just one step. So that one link, for example:
<a href="#{bean.findBidsListFileName()}">Download Your Bids</a>
or, most likely, a jsf commandLink will create the excel file on the back end, save it to the /resources/ location, and seamlessly open a "save" dialog on the user's machine.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…