JSF 2.2 h: inputFile doesn't work with pretty faces

we use Glassfish 4.0 with JSF 2.2 (Mojarra 2.2.0) and PrettyFaces 2.0. When you try to upload a file using h:inputFile with the corresponding form enctype="multipart/form-data" the form action is only triggered if the page is called directy, but nothing happens if a nice url is called. Many other questions have some similar problems (for example, How to use PrimeFaces p: fileUpload? The listener method is never called, and UploadedFile is null ), but most of them seem to use PrimeFaces and have difficulty ordering the filters, etc. Since we want to keep the JSF method for uploading files, I would like to know if there is some configuration of some Mojarra filters that I could skip.

web.xml currently does not contain filter specifications.

jsf file contains only this form

 <h:form enctype="multipart/form-data"> <h:inputFile value="#{fileModel.testFile}"/> <h:commandButton value="Upload" action="#{fileModel.upload}"/> </h:form> 

and bean support is as follows

 @ApplicationScoped @Named public class FileModel { private Part testFile; public Part getTestFile() { return testFile; } public void setTestFile(Part testFile) { this.testFile = testFile; } public void upload() { System.out.println("File Data: " + testFile); } } 

then uncommenting these lines in pretty-config.xml will result in an error, while commenting them out will not.

 <url-mapping id="fileTest"> <pattern value="/file" /> <view-id value="/view/fileTest.xhtml" /> </url-mapping> 

I think the problem can be described in this post from OCPSoft, but there is no solution yet.

+6
source share
2 answers

My suggestion: a page that can be classified through beautiful faces should not contain a submission form! Such a page should be for viewing only, move the file upload form to another regular jsf page without a filter filter

0
source

Just in case, if you want to implement the implementation using simple elements, I already use an implementation similar to this

1.- Configure Filters in Web.xml

 <filter> <filter-name>PrimeFaces FileUpload Filter</filter-name> <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class> </filter> <filter-mapping> <filter-name>PrimeFaces FileUpload Filter</filter-name> <servlet-name>Faces Servlet</servlet-name> <dispatcher>FORWARD</dispatcher> </filter-mapping> 

2.- Page execution

 <h:form id="form-file-upload" enctype="multipart/form-data"> <p:fileUpload auto="false" mode="advanced" value="#{yourBean.file}" fileUploadListener="#{yourBean.fileListener}" invalidSizeMessage="max size 10MB" sizeLimit="10485760"/> </h:form> 

3.- Bean implementation

 @ManagedBean @ViewScoped public class YourBean { private UploadedFile file; public UploadedFile getFile() { return file; } public void setFile(UploadedFile file) { this.file = file; } public void fileListener(FileUploadEvent e){ this.file = e.getFile(); } } 

ShowCase Primefaces

-1
source

All Articles