I’ve created a JSF application, and I want to embed a link in a page which when clicked causes the backing bean to marshall out some xml and force the opening of a save-as download dialogue box so the user can choose a location to save the file. I’ve already written the JAXB code.
How is this done?
Thanks
Set the HTTP
Content-Dispositionheader toattachment. This will pop a Save As dialogue. You can do that usingHttpServletResponse#setHeader(). You can obtain the HTTP servlet response from under the JSF hoods byExternalContext#getResponse().In JSF context, you only need to ensure that you call
FacesContext#responseComplete()afterwards to avoidIllegalStateExceptions flying around.Kickoff example: