This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
The moose likes JSF and the fly likes File upload filter for displaying files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "File upload filter for displaying files" Watch "File upload filter for displaying files" New topic
Author

File upload filter for displaying files

Steve Renard
Ranch Hand

Joined: Apr 27, 2007
Posts: 66
I'm using JSF/Tomahawk library for my application.
For a file upload functionality, I have used t:inputFileUpload tag.
It works fine and am able to upload & download back the file.
But, how do I filter files in the file selection dialog to display only *.doc files?
Any help is appreciated.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
The HTML input type="file" element has an 'accept' attribute which is specified by the W3 HTML specification as optional. You can define in there the content types (mime types) which are to be displayed in the browse dialog only. Unfortunately a lot of webbrowsers doesn't support it. As far now only Opera, which very strictly follows the W3 HTML spec, supports it.

To fullfill this requirement, you need to validate it at the server side at any way. You can use ServletContext#getMimeType() for it to validate the file extension against the mime mapping configuration of the appserver in question. Alternatively you can use URLConnection#guessContentTypeFromName() to validate the file extension against the file type configuration of the underlying operating system.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: File upload filter for displaying files