Using Prettyfaces With Primefaces Upload

primefaces

 

Well to get this to work smoothly with prettyfaces you must play with the configuration a bit.

First in order to make sure that the primefaces upload works, you must make sure that you have these:

  • commons-fileupload and commons-io are present in the webapp’s runtime classpath (just dropping the JARs in /WEB-INF/lib ought to be sufficient).
  • The FileUploadFilter is mapped on the exact <servlet-name> of the FacesServlet as is been definied in your web.xml. If you’ve given it a <servlet-name> of for examplefacesServlet, then you need to edit it in the <filter-mapping> example as well.
  • The enctype of the <h:form> needs to be set to multipart/form-data.
  • In simple file upload with mode="simple", ajax must be disabled on any PrimeFaces command buttons/links by ajax="false".

Now in the web.xml configure the fileupload filter which parses the multipart request. FileUpload filter should map to Faces Servlet:

Notice that I didn’t configure any related Prettyfaces servlet filter!
If you are using a Servlet 3.0 compliant container, PrettyFaces will automatically register the required Servlet Filter; otherwise, make sure PrettyFilter is the first filter in your web.xml file. (The dispatcher elements are required to ensure PrettyFaces intercepts both internal and external requests.)

The trick in the config is the dispatcher inside filter-mapping of the primefaces upload filter

That’s it, you should now be able to upload with Prettyfaces URLs.

Case built with:
Primefaces 3.5
prettyfaces 2.0.4
commons-io 2.4
commons-fileupload 1.3

A helpful stackoverflow post

If you think something is wrong please feel free to comment :)
  1. Ravi says:

    Thank for grate post

    Reply