使用PhaseListener拦截渲染阶段

时间:2012-03-21 07:12:27

标签: jsf-2 phaselistener

我在一个支持bean中调用一个函数,但是在渲染jsf页面之前,我需要进行一些依赖于将呈现的jsf页面的操作(这个页面从一个调用更改为另一个调用)。

我需要在renderize页面之前拦截url的名称,因为我需要执行操作并将结果存储在会话中。

所以我想使用PhaseListener来获取URL,而不是导航案例的名称。

例如:“执行”功能会返回“ ivIndex ”,但我需要获得“ /zone/iv/index.xhtml

我怎么能这样做?

方法:

public String execute(){
  return nameUrl(); // return name of a navigation rule, per example : ivIndex

faces-config.xml中

<navigation-rule>
    <from-view-id>*</from-view-id>

    <navigation-case>
        <from-outcome>ivIndex</from-outcome>
        <to-view-id>/zone/iv/index.xhtml</to-view-id>
    </navigation-case>

1 个答案:

答案 0 :(得分:0)

您可以使用

FacesContext.getCurrentInstance().getViewRoot().getViewId();