Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSF: How to execute some code on every time a navigation rule is executed?

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).

like image 903
Nithin Satheesan Avatar asked Jan 01 '26 03:01

Nithin Satheesan


1 Answers

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>
like image 158
BalusC Avatar answered Jan 03 '26 07:01

BalusC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!