Fileupload and PrettyFaces and JSF 2.2 [duplicate]
Asked Answered
G

2

2

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!

Groundling answered 8/4, 2014 at 16:35 Comment(2)
Can you give more details about the problem you face, such as the error you get?Veinstone
This question is not answered at all with the above mentioned question. This question is not talking about primefaces just pretty and jsf 2.2 fileUpload.Burp
G
7

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?

Groundling answered 10/4, 2014 at 10:29 Comment(2)
I had the same problem, and I also saw that problem. I am using JSF 2.2.x and in that case, use the pastrought with prefix "a". To the form I add to action and the url that you put in your script. Example: <h:form a:action="#{request.contextPath}/test/fileupload.xhtml""></h:form>Nadaba
It looks your suggestion is the only one if we want to keep both the rewrite facility and the jsf fileUpload as well. Thanks for it and also to @Marco Lopez.Burp
L
0

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.

Lilah answered 1/6, 2016 at 16:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.