Dashboard > Spring, JSF and Hibernate Integration > Home > Spring JSF contribution Round 2 NavigationHandlerSupport, PrefixSuffixNavigationHandler
Spring, JSF and Hibernate Integration Log In   View a printable version of the current page.
Spring JSF contribution Round 2 NavigationHandlerSupport, PrefixSuffixNavigationHandler
Added by Rick Hightower, last edited by Rick Hightower on Dec 15, 2005

Avoid XML Hell in JSF using Spring DI

(Files attatched for your review)

One of the biggest complaints developers have about JSF navigation is all of the XML entries that are needed for navigation. Fixed! Spring MVC style with PrefixSuffixNavigationHandler! Please read on.

A reoccurring complaint about JSF is all of the XML you have to create for navigation. The funny part of this is that I did not agree at first. Coming from a Struts background, the Navigation Rules in JSF seemed more natural than what I was use to, and easier to configure. (I was wrong.)

Well a funny thing happened. About a year ago, I worked on a project that used Spring MVC. I really enjoyed working wtih Spring MVC. It is a well designed framework. In Spring MVC you can scale up or scale down how your navigation and view resolving is done. It keeps simple things simple.

Recently, I had to write a custom navigation handler for an internal CRUD framework. Then the idea popped in my head. Why not create a NavigationHandler that works like the Spring style URL resolvers. This way you can avoid XML hell for simple (most common) navigation cases.

Recently, I spoke to Colin S. about some of my ideas for combining concepts out of the Spring MVC world into JSF and adding better support for JSF into Spring. There is a list (which I will publish) of 20 or so ideas that would encompass about 40 or so classes. As part of that effort, I wrote a series of classes that allow NavigationHandler's to use Springs DI (dependency injection) and AOP support.

The NavigationHandlerSupport class allows NavigationHandlers to be configured in Spring's applicationContext. JSF NavigationHandler's are composed into a chain of handlers by the JSF framework. Each handler can can handle the navigation or delegate handing to the next handler in the chain. This is done by passing the next NavigationHandler in the chain as an argument to the constructor. The trick in NavigationHandlerSupport was to allow the same functionality and allow it to be configured in Spring.

It was tricky but possible as evidenced by the PrefixSuffixNavigationHandler class which allows developers to skip navigation rules for simple navigation cases (the bulk).

The developers can specify the prefix, suffix and an optional prefix marker via Spring dependency injection (if you use this NavigationHandler in conjuction with the NavigationHandlerSupport class, which is optional).

For example:

Thus if an action handler method on a backing bean returned "_foo", the PrefixSuffixNavigationHandler will select /pages/foo.jsp as the next view URI. You don't need navigation rules in faces-config. However, your other navigation rules will work just fine.

The Defaults for PrefixSuffixNavigationHandler are as follows:
The default identificationToken is "_".
The default prefix is "/pages/".
And the default suffix is ".jsp".

You can override any of the defaults using Spring dependency injection.

This is going to be a time saver for the most common style of navigation. For more details, please read the JavaDocs of the attached files.

Looks like my earlier submission was accepted by Colin. This one may have been accepted as well.

Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 1.4.2 Build:#214 Jun 30, 2005) - Bug/feature request - Contact Administrators