问题
This question already has an answer here:
- Primefaces FileUpload with PrettyFaces and JSF 2.2.3 3 answers
I\'ve tried the solution from: Primefaces FileUpload with PrettyFaces and JSF 2.2.3
But it doesn\'t work for a few files (tested under tomcat 7.0.50).
One of the files is: http://ftp.carnet.hr/misc/apache//xerces/j/source/Xerces-J-src.2.11.0-xml-schema-1.1-beta.zip
Has someone a better solution for this problem (other than removing the urlmapping)?
EDIT: There is no error/exception thrown! File is shown in the PrimeFaces FileUpload, but the listener is not fired! JSF2.2 inputFile doesn\'t work, too!
回答1:
I've found a solution for my problem.
The problem is the action attribute of the forms which are used for the upload. PrettyFaces changes the action attribute to the new pretty-url.
If you change the action attribute to the real url (the one with .xhtml,.jsf,...) the fileupload works again and the allowCasualMultipartParsing="true" entry in the context-file(tomcat) is not needed anymore.
To change the path place this script into the view (your xhtml-file; jquery needed):
<script type="text/javascript">
$(document).ready(function() {
$("form[enctype='multipart/form-data']").attr("action","#{request.contextPath}/test/fileupload.xhtml");
});
</script>
Now the fileupload is working for all of my files including the ones which not worked (even with allowCasualMultipartParsing="true" solution).
Tested with Primefaces4.0 FileUpload-Component.
EDIT:
Is there any other better solution?
回答2:
On my similar project (JSF+JQuery+PrettyFaces/Rewrite), the action and listener functions were called, but the setPart(Part part) function wasn't called (h:inputFile value="#{bean.part}).
I found two solutions, one was to add @MultipartConfig (and @WebServlet + extends HttpServlet) to beans that received upload Part files. However, just adding the allowCasualMultipartParsing="true" entry was sufficient for my project.
来源:https://stackoverflow.com/questions/22943066/fileupload-and-prettyfaces-and-jsf-2-2