URL-rewriting in 60 seconds: JBoss Forge and PrettyFaces

Do you have an existing Maven-based Java EE application that you’d like to clean up a bit in the browser? Do your URLs look too much like this:
http://example.com/app/sillyServletName/someStuff?sillyParam=22&sillyOtherParam=profile
And not enough like this?
http://example.com/app/profile/22
Are you building a new application, and don’t want to sacrifice anything when it comes to usability or SEO capabilities? Well, URL-rewriting is your answer, and it’s easy to get started, even easier using JBoss Forge.PrettyFaces is a URL-rewriting solution for Servlet, JavaEE, and JSF applications, is highly extendable, and easy to install; however, we weren’t satisfied with the experience of forcing people to create their own configuration file, trying to find which version to install, and having problems when they try to mix information from different sources. JBoss Forge looked like the perfect opportunity to make your job even easier, and it’s through JBoss Forge that we think we’ve accomplished our goals; we’d like to know if you agree:

With those three commands, we just created a new Servlet 3.0 web-application, installed PrettyFaces, and added a URL-mapping from ‘/’ to the index page. Now that’s powerful! Also, did I mention that this application is now ready to be deployed on a Servlet Container or Application Server like JBoss AS or Tomcat? Life is so hard these days…

So what does that mean? What actually happened?

First, no more hunting for configuration files or making sure that your XML has the right schema. Second, you no longer have to search for the available versions to install, and third, all of your POM configuration is done for you.
In short, the prettyfaces-forge-plugin has set up the following configurations for you:

Sure, we could have created and updated these configurations ourselves, that’s pretty easy too, but this is just one more simplification; we want your lives to be as easy as possible. Even better, the PrettyFaces Plugin supports <TAB>-completion of mapping-IDs and view-IDs; when you type a command, you don’t have to look at the configuration file because most available options are just a <TAB> away. (When in doubt, press <TAB>)

Which in turn updated our pretty-config.xml to include an action on the index page. Notice that we had to install JSF in order to continue. The action will only trigger if the page being executed is run through the FacesServlet.

Conclusion

Please note that you can also use all of the tools described here on an existing Maven-based web application, and you do not need to create a new project just to try this. We hope that this simple plugin makes your life a little bit easier, and more productive. We also welcome your feedback. Tell us how we can improve! For those who are curious, the source code for the PrettyFaces Forge Plugin is located here, on GitHub.

About the author:

Lincoln Baxter, III is a Principal Software Engineer at Red Hat, working on JBoss open-source projects; most notably as creator & project lead of JBoss Forge, and author of Errai UI. This blog represents his personal thoughts and perspectives, not necessarily those of his employer.

He is a founder of OCPsoft, the author of PrettyFaces and Rewrite, the leading URL-rewriting extensions for Servlet, Java EE, and Java web frameworks; he is also the author of PrettyTime, social-style date and timestamp formatting for Java. When he is not swimming, running, or playing Ultimate Frisbee, Lincoln is focused on promoting open-source software and making web-applications more accessible for small businesses, individuals.