Sunday, November 21, 2010

Spring & JSF

In a JSF based project, we have a library with common components. In our menu component, we have overriden the isRendered method to follow authorization rules. So, displaying a menu depends on the user being logged. Taking into account that is a common library, the implementation of the authorization rules must be fullfilled by each project using the library.

The menu component has a method to evaluate visibility regarding authorization permit, let's say checkVisibility. The trick is call a static class inside this method. The static class, let's say CheckStatic, has just a single method evaluateVisibility . CheckStatic has an interface CheckingRulesInterface. The only method calls the interface method that really checks visiblity. The project using the menu item should implement the interface. Using Spring factory bean definitions, we can configure the static class with the proper interface implementation.


MenuItem{
checkVisibility(){
return CheckStatic.evaluateVisibility();
}
}
CheckStatic{
CheckingRulesInterface checkIt;
evaluateVisibility(){
return checkIt.reallyCheckIt();
}
}

No comments: