This depends on browser configuration as to files with csv
extension and the Content-Type
header on the HTTP response. This defaults usually to text/csv
(you can figure out it in browser's HTTP traffic monitor which you can get by pressing F12 in browser and opening "Network" tab). Most browsers will by default display text/*
content inline. But the enduser can manipulate the default browser behavior, usually during the first time of download when the browser asks what to do with the file, and then it's remembered for future actions. This is beyond server's (your) control.
You can manipulate the default value of the Content-Type
header of file with the csv
extension by a <mime-mapping>
in webapp's web.xml
like below:
<mime-mapping>
<extension>csv</extension>
<mime-type>application/csv</mime-type>
</mime-mapping>
Most browsers will associate application/*
content as an attachment, or will already have a default application associated, e.g. Excel, or will ask the enduser what to do with it. The result is also beyond server's control.
You can force a Save As dialog by the new HTML5 download
attribute of the <a>
element, wherein you (re)specify the sole filename like below:
<a href="#{request.contextPath}/resources/file/download.csv"
download="download.csv">download</a>
Note that you can perfectly embed plain HTML in JSF and you also don't need <h:outputText>
over all place for static text. See also Is it suggested to use h:outputText for everything?
Or, if you're already on JSF 2.2, which supports passthrough attributes, and you insist in using <h:outputLink>
for the job which doesn't support the download
attribute, then you can do as below:
<... xmlns:a="http://xmlns.jcp.org/jsf/passthrough">
...
<h:outputLink value="#{request.contextPath}/resources/file/download.csv"
a:download="download.csv">download</h:outputLink>
See also Custom HTML tag attributes are not rendered by JSF.