JSF - 自定义 NavigationHandler 结果值无效? [英] JSF - custom NavigationHandler outcome values invalid?

查看:14
本文介绍了JSF - 自定义 NavigationHandler 结果值无效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I wrote myself a custom NavigationHandler very similar to following one but just using a stack to save the history:

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 中注册这个:

Registering this one in the faces-config.xml:

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

导致以下日志警告和存在先前工作链接的消息:

Results in following log warning and a message where a previously working link was present:

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

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

有什么问题?

推荐答案

从 JSF 2 开始,NavigationHandler 已替换为 ConfigurableNavigationHandler.<h:link> 等所有 JSF 2 特定标签/组件都依赖于它.NavigationHandler 是为了向后兼容而保留的.

Since JSF 2, the NavigationHandler has been replaced by ConfigurableNavigationHandler. All JSF 2 specific tags/components like <h:link> and so on are relying on it. The NavigationHandler is kept for backwards compatibility.

这是一个如何正确扩展 ConfigurableNavigationHandler 的启动示例:

Here's a kickoff example how to properly extend 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 - 自定义 NavigationHandler 结果值无效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆