PrimeFaces upload with PrettyFaces enabled

Goal

To make your Primefaces upload component work together with Prettyfaces semantic URLs

Description

Do you have an application with Primefaces’ fileUpload component that suddenly stopped working when you start using Prettyfaces to provide semantic URLs as asked in this page?

If you do, maybe this recipe suits your needs!

How to

As usual, make sure you define Primefaces upload filter in your web.xml or web-fragment.xml file. However, unlike what you usually need to do, in order to make it usable together with Prettyfaces, that filter needs to be associated to the dispatcher type “FORWARD”, as follows:

<filter>
  <filter-name>PrimeFaces FileUpload Filter</filter-name>
  <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
  ... init params - not shown for simplicity reasons
</filter>
<filter-mapping>
  <filter-name>PrimeFaces FileUpload Filter</filter-name>
  <servlet-name>Faces Servlet</servlet-name>
  <dispatcher>FORWARD</dispatcher>
</filter-mapping>

Explanations

Without the association of Primefaces’ filter to the “forward” dispatcher type, Prettyfaces filters do not let the upload filter from Primefaces to be able to process the request. So, if you do associate the upload filter to the forward dispatcher, the filter is now able to be invoked and process the request

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s