A previous
post discussed how to inject the FacesContext
into managed
beans using a
broker. This post demonstrates how to build on that approach with
greater levels of abstraction.
It is generally possible to remove direct JSF dependencies from managed bean code. You might want to do this to reduce coupling, improve cohesion or in the interests of writing testable code.
The code was written against Java 6, JSF 2 and JUnit 4 but the approach could be adapted to earlier versions of all of these.