每当执行navigation rule
时,我是否可以执行某些代码。基本上我要做的是拥有一个JourneyTracker
bean,它将保持当前的旅程状态(就像用户所在的当前页面一样)。
答案 0 :(得分:4)
您可以使用自定义NavigationHandler
。基本上,只需按如下方式扩展该抽象类:
public class MyNavigationHandler extends NavigationHandler {
private NavigationHandler wrapped;
public MyNavigationHandler(NavigationHandler wrapped) {
this.wrapped = wrapped;
}
@Override
public void handleNavigation(FacesContext context, String from, String outcome) {
// Do your job here. Just check if "from" and/or "outcome" matches the desired rule.
wrapped.handleNavigation(context, from, outcome); // Important! This will perform the actual navigation.
}
}
要让它运行,只需在faces-config.xml
:
<application>
<navigation-handler>com.example.MyNavigationHandler</navigation-handler>
</application>