Rich file upload showing all files on add, even fo

2019-07-22 19:05发布

<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..

2条回答
虎瘦雄心在
2楼-- · 2019-07-22 19:37

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:

查看更多
不美不萌又怎样
3楼-- · 2019-07-22 19:39

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>
查看更多
登录 后发表回答