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 theh: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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<url-mapping id="blog"> | |
<pattern value="/blog/#{url}" /> | |
<view-id value="/blog.jsf" /> | |
</url-mapping> |
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Post a Comment
Post a Comment