Ste*_*ote 6 jsf-2 phaselistener
在我的JSF2应用程序中,我有一个phaselistener需要在RENDER_RESPONSE之前执行,但是在JSF构建了viewroot之后.
首先,我所做的是在faces-config中注册我的PhaseListener.然后调用侦听器,但是当我执行beforePhase时,getViewRoot().getChildren()仍然是空的.
其次,我通过在我的xhtml页面上添加以下内容找到了如何做到这一点:
<f:phaseListener type="be.application.PolicyController" />
Run Code Online (Sandbox Code Playgroud)
这很好用,但是将它添加到我的每个页面都会非常繁琐.因此,我正在寻找为我的申请做一次的可能性.
有什么想法可以做到这一点?
为PreRenderViewEventfaces-config 注册一个系统事件监听器:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
<application>
<system-event-listener>
<system-event-listener-class>test.PreRenderViewListener</system-event-listener-class>
<system-event-class>javax.faces.event.PreRenderViewEvent</system-event-class>
</system-event-listener>
</application>
</faces-config>
Run Code Online (Sandbox Code Playgroud)
监听器的示例:
public class PreRenderViewListener implements SystemEventListener {
@Override
public void processEvent(SystemEvent event) throws AbortProcessingException {
UIViewRoot root = (UIViewRoot) event.getSource();
System.out.println(root.getChildCount());
}
@Override
public boolean isListenerForSource(Object source) {
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3689 次 |
| 最近记录: |