Pretty-faces is a simple URL rewriting engine. All sorts of SEO is possible and it is really easy. We faced very small problem while using this long with Prime-Faces. The problem us file upload in Ajax environment stopped working because some how it is not able to identify rewritten URL.

Solution

After some Investigation, I found that we can make file upload work, if some how we can find actual url along with query parameter from pretty faces and add this on the h:form component action. I tweaked some solutions available in the fourms and created a new one to support my requirement.
Sample Pretty Faces Rewrite Rule
<url-mapping id="blog">
<pattern value="/blog/#{url}" />
<view-id value="/blog.jsf" />
</url-mapping>
view raw web.xml hosted with ❤ by GitHub
So the URL in address bar looks like
http://host.com/blog/sample-post
The Rewrite Rule maps the request internally to
http://host.com/blog?url=sample-post
Actual URL Generation Code
PrettyContext context = PrettyContext.getCurrentInstance(fc);
if (context.isPrettyRequest()) {
StringBuilder builder = new StringBuilder(context.getContextPath());
UrlMapping mapping = context.getCurrentMapping();
builder.append(mapping.getViewId());
QueryString query = QueryString.build(context.getRequestQueryString().getParameterMap());
Map < String, String[] > params = new HashMap < String, String[] > ();
List < PathParameter > parameters = mapping.getPatternParser().parse(context.getRequestURL());
for (PathParameter parameter: parameters) {
params.put(parameter.getName(), new String[] {
parameter.getValue()
});
}
query.addParameters(params);
builder.append(query.toQueryString());
return builder.toString();
}
return null;