I’m trying to add a very simple file input to my webapp which I’m doing using JSF2.0 and RichFaces 3.3.3, the thing is I really dislike the richfaces fileInput component and I’m looking for something simpler (in terms of use and looks), so far I’ve found:
- tomahawk’s fileInput – but tomahawk only supports JSF1.2
- trinidad fileInput – but trinidad for JSF2.0 is in alpha stage
- primefaces – but of course they won’t work with RichFaces 3.3.3 (only 4.0 which are in beta)
Are there any other options? I need something really simple like a normal html file input component.
You basically need to do two things:
Create a Filter which puts the
multipart/form-dataitems in a custom map and replace the original request parameter map with it so that the normalrequest.getParameter()process keeps working.Create a JSF 2.0 custom component which renders a
input type="file"and which is aware of this custom map and can obtain the uploaded files from it.@taher has already given a link where you could find insights and code snippets. The JSF 2.0 snippets should be reuseable. You yet have to modify the
MultipartMapto use the good ‘ol Apache Commons FileUpload API instead of the Servlet 3.0 API.If I have time, I will by end of day rewrite it and post it here.
Update: I almost forgot you, I did a quick update to replace Servlet 3.0 API by Commons FileUpload API, it should work:
You still need both the
MultipartFilterandMultipartRequestclasses as described in this article. You only need to remove the@WebFilterannotation and map the filter on anurl-patternof/*along with an<init-param>oflocationwherein you specify the absolute path where the uploaded files are to be stored. You can use the JSF 2.0 custom file upload component as described in this article unchanged.