Is there any way I can execute some code whenever a navigation rule is executed. Basically what I am trying to do is to have a JourneyTracker bean which will hold the current state of the journey (like the current page the user is in).
You can use a custom NavigationHandler for this. Basically, just extend that abstract class as follows:
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.
}
}
To get it to run, just register it as follows in faces-config.xml:
<application>
<navigation-handler>com.example.MyNavigationHandler</navigation-handler>
</application>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With