Fileupload and PrettyFaces and JSF 2.2 [duplicate]

六眼飞鱼酱① 提交于 2019-11-26 09:57:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!