Rectangle 27 0

jsf 2 JSF 2 and PostRedirectGet?


<application>
    <navigation-handler>com.example.RedirectNavigationHandler</navigation-handler>
</application>
ConfigurableNavigationHandler
NavigationHandler
extends ConfigurableNavigationHandler
extends NavigationHandler
package com.example;

import java.util.Map;
import java.util.Set;

import javax.faces.application.ConfigurableNavigationHandler;
import javax.faces.application.NavigationCase;
import javax.faces.application.NavigationHandler;
import javax.faces.context.FacesContext;

public class RedirectNavigationHandler extends ConfigurableNavigationHandler {

    private NavigationHandler parent;

    public RedirectNavigationHandler(NavigationHandler parent) {
        this.parent = parent;
    }

    @Override
    public void handleNavigation(FacesContext context, String from, String outcome) {
        if (!outcome.endsWith("?faces-redirect=true")) {
            outcome += "?faces-redirect=true";
        }

        parent.handleNavigation(context, from, outcome);        
    }

    @Override
    public NavigationCase getNavigationCase(FacesContext context, String fromAction, String outcome) {
        if (parent instanceof ConfigurableNavigationHandler) {
            return ((ConfigurableNavigationHandler) parent).getNavigationCase(context, fromAction, outcome);
        } else {
            return null;
        }
    }

    @Override
    public Map<String, Set<NavigationCase>> getNavigationCases() {
        if (parent instanceof ConfigurableNavigationHandler) {
            return ((ConfigurableNavigationHandler) parent).getNavigationCases();
        } else {
            return null;
        }
    }

}

Hi, Albert. You can add code to handler and check if the request is an AJAX request getting a PartialViewContext from FaceContext and then invoking PartialViewContext.isAJAXRequest download.oracle.com/javaee/6/api/javax/faces/context/.

Is possible to make this handler work when action method return void (stay on the same page) <h:commandButton action="#{bean.voidMethod}"/> ?

Register it as follows in faces-config.xml:

You could do this with a custom ConfigurableNavigationHandler. Here's a kickoff example:

Note
Rectangle 27 0

jsf 2 JSF 2 and PostRedirectGet?


<application>
    <navigation-handler>com.example.RedirectNavigationHandler</navigation-handler>
</application>
ConfigurableNavigationHandler
NavigationHandler
extends ConfigurableNavigationHandler
extends NavigationHandler
package com.example;

import java.util.Map;
import java.util.Set;

import javax.faces.application.ConfigurableNavigationHandler;
import javax.faces.application.NavigationCase;
import javax.faces.application.NavigationHandler;
import javax.faces.context.FacesContext;

public class RedirectNavigationHandler extends ConfigurableNavigationHandler {

    private NavigationHandler parent;

    public RedirectNavigationHandler(NavigationHandler parent) {
        this.parent = parent;
    }

    @Override
    public void handleNavigation(FacesContext context, String from, String outcome) {
        if (!outcome.endsWith("?faces-redirect=true")) {
            outcome += "?faces-redirect=true";
        }

        parent.handleNavigation(context, from, outcome);        
    }

    @Override
    public NavigationCase getNavigationCase(FacesContext context, String fromAction, String outcome) {
        if (parent instanceof ConfigurableNavigationHandler) {
            return ((ConfigurableNavigationHandler) parent).getNavigationCase(context, fromAction, outcome);
        } else {
            return null;
        }
    }

    @Override
    public Map<String, Set<NavigationCase>> getNavigationCases() {
        if (parent instanceof ConfigurableNavigationHandler) {
            return ((ConfigurableNavigationHandler) parent).getNavigationCases();
        } else {
            return null;
        }
    }

}

Hi, Albert. You can add code to handler and check if the request is an AJAX request getting a PartialViewContext from FaceContext and then invoking PartialViewContext.isAJAXRequest download.oracle.com/javaee/6/api/javax/faces/context/.

Is possible to make this handler work when action method return void (stay on the same page) <h:commandButton action="#{bean.voidMethod}"/> ?

Register it as follows in faces-config.xml:

You could do this with a custom ConfigurableNavigationHandler. Here's a kickoff example:

Note