PrettyFaces
SEO | Dynamic Parameters | Links | Bookmarks | Bookmarking | Navigation | JSF | JSF2 | UrlRewrite
Simple, effective, bookmark, JSF
PrettyFaces is an OpenSource extension for JSF 1.1, 1.2 and 2.0, which enables creation of bookmark-able, pretty URLs. PrettyFaces solves this problem elegantly, including features such as: page-load actions, seamless integration with faces navigation, dynamic view-id assignment, managed parameter parsing, and configuration-free compatibility with other JSF frameworks.
SEO and Consistency:
Any business knows how important Search Engine Optimization can be for sales. PrettyFaces allows SEO-friendly URLs, and improved customer experience. Give your site a uniform, well understood feeling, from the address bar to the buy button.
Downloads: ↓ (LGPL3)Dependencies:JSF1.1, 1.2 or 2.0 Upcoming features:Zero configuration in a Servlet 3.0 environment, automatic reloading of pretty-config.xml for more rapid development using the new JSF2 ProjectStage | PrettyFaces requires separate downloads of dependencies. Also, we encourage feedback for all of our products, so please, if you have questions, concerns, suggestions, or would like to contribute – email the user-group, or open an issue.
View the documentation or FAQ. |
From @ocpsoft and @lincolnthree
Features:
- URL Rewriting — Replace jsf views: “/faces/page.jsf” with pretty, SEO-friendly, URLS: “/optimized/page”; The client browser never sees your JSF View ID
- Dynamic view IDs — Now with dynamic view ID mapping for URLs (through El method expressions,) you can show different views based on run-time conditions, effectively de-coupling the URL from the JSF view.
- Page-load actions — Call one or more action-methods, at one or more phases, before rendering a view.
- Managed parameter parsing — HTTP parameters parsed from URLs are stored in managed beans, simply get a reference to your parameter bean for easy access from other Java classes.
- Navigation by ID — Define your page IDs in one place, reference them easily in action-methods and components, using standard JSF navigation techniques.
- Integrated validation — For URL and query-parameters, able to re-use existing JSF validator objects.
- Easy to configure — Requires only one consolidated XML configuration file.
What makes PrettyFaces different:
View a slideshare presentation on why URL Rewriting is important, or a brief overview of the problems PrettyFaces solves.
View the documentation.
FAQ:
Q. Can I use PrettyFaces to handle UrlRewriting for other resources on my server as well?
A. Yes. PrettyFaces still requires a configured JSF instance to function, but it can be used to map a URL to any resource in the Servlet Container – without invoking FacesServlet. Values will be injected into JSF beans as usual, but PrettyFaces Action methods will not trigger (since no JSF lifecycle executes for non-Faces requests.)
For example:
<pretty-config xmlns="http://ocpsoft.com/prettyfaces-xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://ocpsoft.com/prettyfaces-xsd http://ocpsoft.com/xml/ns/prettyfaces/pretty-1.0.xsd"> <url-mapping id="login"> <pattern> /login </pattern> <view-id> /legacy/user/login.jsp </view-id> <!-- Non JSF View Id --> </url-mapping> <url-mapping id="register"> <pattern> /register </pattern> <view-id>/faces/user/register.jsf</view-id> <!-- JSF View Id --> </url-mapping> </pretty-config>
Q. Why do my Tomahawk / MyFaces components, or other 3rd party addons, break when I use PrettyFaces?
A. Since PrettyFaces intercepts mapped HttpRequests then forwards those requests to JSF, it is necessary to enable any additional filters between PrettyFaces and JSF to listen to Servlet Forwards. This is done in the web.xml deployment descriptor by adding the following dispatcher elements to any needed Filters:
For example:
<filter-mapping> <filter-name>springSecurityFilterChain</filter-name> <url-pattern>/*</url-pattern> <dispatcher>FORWARD</dispatcher> <dispatcher>REQUEST</dispatcher> </filter-mapping>
Q. Why, when using MyFaces, am I getting a NullPointerException when I try to use normal faces-navigation?
A. Some MyFaces versions do not completely comply with the JSF specification, thus the ViewRoot is null when the request is processed. There is a patch/workaround, which can be added to fix this issue. You must add this ViewHandler to your faces-config.xml.
Q. Can I configure PrettyFaces via Annotations?
A. No – this is not currently supported, but if someone wants to submit a patch, we’ll be more than happy to discuss your design.
Q. How do I enable logging, so that I can tell what the heck is really going on?
A. Create or update your log4j.properties file with the following values:
### direct log messages to stdout ### log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target=System.out log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n log4j.rootLogger=warn, stdout ### Log for OcpSoft log4j.logger.com.ocpsoft=infoQ. Can I map and process URLs that span a dynamic number of ‘/’ characters?
A. Yes, please read section 3.4 of the docs.
Q. How do I save FacesMessage objects after performing a redirect or pretty:redirect?
A. You need to configure the optional MultiPageMessagesSupport PhaseListener (or something like it)
<?xml version='1.0' encoding='UTF-8'?> <faces-config xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd" version="1.2"> <lifecycle> <phase-listener> com.ocpsoft.pretty.application.MultiPageMessagesSupport </phase-listener> </lifecycle> </faces-config>
See this article for a full explanation of how this works.
Q. Does PrettyFaces work on IBM’s WebSphere?
A. Yes, but websphere requires a custom setting in order to behave like a sane server.

