JSF - 自定义 NavigationHandler 结果值无效?

标签 jsf jakarta-ee navigation

我自己写了一个自定义的 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

问题是什么?

最佳答案

从 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 - 自定义 NavigationHandler 结果值无效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12045442/

相关文章:

drupal - 如何让菜单面包屑出现在 Drupal 7 的导航栏中?

jquery - 显示 : table-cell with text-align: center

javascript - PrimeFaces 重写 PDF 路径以在新窗口中显示

jsf - 如何防止表单在同一html页面提交时重置其他表单

Java EE 应用程序客户端容器

java - Spring MVC HashMap 表单集成

jsf - 在 primefaces 的新选项卡中打开菜单项页面

jsf - 如何流式传输文件下载并显示 JSF faces 消息?

java - 如何在Java中输入def注解

html - 响应式设计topnavigation