【问题标题】:Get current page name with JSF/PrettyFaces使用 JSF/PrettyFaces 获取当前页面名称
【发布时间】:2012-01-06 20:42:30
【问题描述】:

我正在使用 PrettyFaces 作为 url 重写库,如下所示:

@URLMappings(mappings = {
        @URLMapping(id = "page1", pattern = "/page1", viewId = "/faces/pages/page1.xhtml"),
        @URLMapping(id = "page2", pattern = "/page2", viewId = "/faces/pages/page2.xhtml") })

我可以得到viewId如下:

String viewId = facesContext.getViewRoot().getViewId();

这将返回类似:/faces/pages/page1.xhtml

我想知道是否有一种直接的方法可以让视图的模式或 id 返回类似 page1 的内容,或者我必须在上面的代码中使用 substring获取viewId?

【问题讨论】:

    标签: java jsf-2 url-rewriting prettyfaces


    【解决方案1】:

    是的 :) 只需致电:

    PrettyContext.getCurrentInstance().getCurrentMapping().getId();
    

    或者,.getPattern() 或者等等...

    干杯:)

    【讨论】:

    • 是否可以在xhtml页面中获取映射id?
    猜你喜欢
    • 2013-04-17
    • 1970-01-01
    • 1970-01-01
    • 2016-12-18
    • 2013-07-29
    • 2018-04-20
    • 2011-06-17
    • 2012-05-15
    • 1970-01-01
    相关资源
    最近更新 更多