问题
<rich:fileUpload fileUploadListener="# {bean.fileUploadAction}"
immediateUpload="true" acceptedTypes="xls" maxFilesQuantity="1">
</rich:fileUpload>
in rich file uplaod i given acceptedTypes="xls" ,but on "add" in the file select box Files of types is showing all. I want to restrict it to only some specific format how can i do that. Any kind of help is appriciated,thanks in advance..
回答1:
This alternative way may solve your problem to some extent. Add an onclick
event to your <rich:fileUpload
components as below.
<rich:fileUpload onclick="this.getElementsByTagName('input')[0].setAttribute('accept', 'application/vnd.ms-excel');" fileUploadListener="# {bean.fileUploadAction}"
immediateUpload="true" maxFilesQuantity="1">
</rich:fileUpload>
回答2:
That's only possible if it generates the following HTML (and the page is opened by a HTML5 compatible webbrowser):
<input type="file" ... accept="application/vnd.ms-excel" />
However, it doesn't do that. Instead, it generates a simple HTML4 compatible <input type="file">
without the accept
attribute and does a file extension check on the selected file by JavaScript.
So you're out of luck here. You'd basically need to replace the <rich:fileUpload>
by another component which generates exactly the desired HTML with the proper accept
attribute set on <input type="file">
. As far as I see now, no one JSF component library offers such a component yet. You might need to homegrow it.
See also:
- HTML5 specification - the accept attribute of type=file
来源:https://stackoverflow.com/questions/14215770/rich-file-upload-showing-all-files-on-add-even-for-acceptedtypes-xls