JSF - 定制NavigationHandler结果值无效?(JSF - custom Navi

2019-07-31 02:25发布

我写我自己的自定义NavigationHandler非常相似,下面一个只是使用堆栈来保存历史:

http://jsfatwork.irian.at/book_de/custom_component.html#!idx:/custom_component.html:fig:backnavigationhandler-code

public class HistoryNavigationHandler extends NavigationHandler
{
    private final NavigationHandler navigationHandler;

    private final Stack<String> outcomes;

    public HistoryNavigationHandler(final NavigationHandler navigationHandler)
    {
        this.navigationHandler = navigationHandler;
        this.outcomes = new Stack<String>();
    }

    @Override
    public void handleNavigation(final FacesContext context, final String fromAction, final String outcome)
    {
        if (outcome != null)
        {
            if (outcome.equals("back"))
            {
                final String lastViewId = this.outcomes.pop();

                final ViewHandler viewHandler = context.getApplication().getViewHandler();
                final UIViewRoot viewRoot = viewHandler.createView(context, lastViewId);
                context.setViewRoot(viewRoot);
                context.renderResponse();

                return;
            }
            else
            {
                this.outcomes.push(context.getViewRoot().getViewId());
            }
        }
        this.navigationHandler.handleNavigation(context, fromAction, outcome);
    }
}

注册这一个在faces-config.xml中:

<navigation-handler>
    package.HistoryNavigationHandler
</navigation-handler>

结果下面的日志警告和消息,其中以前的工作环节存在:

Warning: jsf.outcome.target.invalid.navigationhandler.type

Something like: this link is disabled because a navigation case could not be matched

问题是什么?

Answer 1:

由于JSF 2, NavigationHandler已取代ConfigurableNavigationHandler 。 所有JSF 2特定的标记/组件等<h:link>等依靠它。 该NavigationHandler保持向后兼容。

这里有一个例子开球如何正确扩展ConfigurableNavigationHandler

public class HistoryNavigationHandler extends ConfigurableNavigationHandler {

    private NavigationHandler wrapped;

    public HistoryNavigationHandler(NavigationHandler wrapped) {
        this.wrapped = wrapped;
    }

    @Override
    public void handleNavigation(FacesContext context, String from, String outcome) {

        // TODO: Do your job here. 

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

    @Override
    public NavigationCase getNavigationCase(FacesContext context, String fromAction, String outcome) {
        return (wrapped instanceof ConfigurableNavigationHandler)
            ? ((ConfigurableNavigationHandler) wrapped).getNavigationCase(context, fromAction, outcome)
            : null;
    }

    @Override
    public Map<String, Set<NavigationCase>> getNavigationCases() {
        return (wrapped instanceof ConfigurableNavigationHandler)
            ? ((ConfigurableNavigationHandler) wrapped).getNavigationCases()
            : null;
    }

}


文章来源: JSF - custom NavigationHandler outcome values invalid?