简体   繁体   English

使用PhaseListener拦截渲染阶段

[英]Using an PhaseListener to intercept the rendering phase

I am calling a function in a backing bean, but before rendering jsf page, I need to make some operations that depend on the jsf page that will render (this page changes from one call to another). 我在后备Bean中调用一个函数,但是在呈现jsf页面之前,我需要进行一些依赖于将呈现的jsf页面的操作(此页面从一个调用变为另一个调用)。

I need to intercept the name of the url, before renderize page, because I need to perform operations and store the result in session. 在渲染页面之前,我需要拦截url的名称,因为我需要执行操作并将结果存储在会话中。

So I want to use a PhaseListener to get the URL, and not the name of navigation case. 因此,我想使用PhaseListener来获取URL,而不是导航用例的名称。

Eg: The function ' execute ' returns ' ivIndex ' but I need to get ' /zone/iv/index.xhtml '. 例如:函数' execute '返回' ivIndex ',但我需要获取' /zone/iv/index.xhtml '。

How I can do this? 我该怎么做?

method: 方法:

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

faces-config.xml 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>

您可以使用

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM