FacesContextListener 实现
FacesContextListener implementation
尝试实施 FacesContextListener, which seems to be the ideal place for the current challenge we are facing, I still struggle with its implementation. Attempts to declare it in the faces-config.xml or a construction similar to the ApplicationListener 失败(因为我可能引用了错误的东西(当然 class 本身除外))。
有人可以提供有关 FacesContextListener 实施的指导/简短示例吗?
创建一个实现 FacesContextListener 接口的 Java class。
package ch.hasselba.xpages;
import javax.faces.context.FacesContext;
import com.ibm.xsp.event.FacesContextListener;
public class MyFacesContextListener implements FacesContextListener {
public void beforeContextReleased(FacesContext fc) {
System.out.println("beforeContextReleased");
}
public void beforeRenderingPhase(FacesContext fc) {
System.out.println("beforeRenderingPhase");
}
}
现在,将 class 的实例添加到您的 XPage:
importPackage( ch.hasselba.xpages )
var fcl = new ch.hasselba.xpages.MyFacesContextListener();
facesContext.addRequestListener( fcl );
希望对您有所帮助!
编辑:
这是一个带有匿名监听器的 Java 实现:
package ch.hasselba.xpages;
import javax.faces.context.FacesContext;
import com.ibm.xsp.context.FacesContextExImpl;
import com.ibm.xsp.event.FacesContextListener;
public class MyObject {
private transient FacesContextListener mFCListener;
public MyObject() {
mFCListener = new FacesContextListener() {
public void beforeContextReleased(FacesContext fc) {
System.out.println("Before Releasing.");
}
public void beforeRenderingPhase(FacesContext fc) {
System.out.println("Before Rendering.");
}
};
FacesContextExImpl fc = (FacesContextExImpl) FacesContext.getCurrentInstance();
fc.addRequestListener( this.mFCListener );
}
}
尝试实施 FacesContextListener, which seems to be the ideal place for the current challenge we are facing, I still struggle with its implementation. Attempts to declare it in the faces-config.xml or a construction similar to the ApplicationListener 失败(因为我可能引用了错误的东西(当然 class 本身除外))。
有人可以提供有关 FacesContextListener 实施的指导/简短示例吗?
创建一个实现 FacesContextListener 接口的 Java class。
package ch.hasselba.xpages;
import javax.faces.context.FacesContext;
import com.ibm.xsp.event.FacesContextListener;
public class MyFacesContextListener implements FacesContextListener {
public void beforeContextReleased(FacesContext fc) {
System.out.println("beforeContextReleased");
}
public void beforeRenderingPhase(FacesContext fc) {
System.out.println("beforeRenderingPhase");
}
}
现在,将 class 的实例添加到您的 XPage:
importPackage( ch.hasselba.xpages )
var fcl = new ch.hasselba.xpages.MyFacesContextListener();
facesContext.addRequestListener( fcl );
希望对您有所帮助!
编辑: 这是一个带有匿名监听器的 Java 实现:
package ch.hasselba.xpages;
import javax.faces.context.FacesContext;
import com.ibm.xsp.context.FacesContextExImpl;
import com.ibm.xsp.event.FacesContextListener;
public class MyObject {
private transient FacesContextListener mFCListener;
public MyObject() {
mFCListener = new FacesContextListener() {
public void beforeContextReleased(FacesContext fc) {
System.out.println("Before Releasing.");
}
public void beforeRenderingPhase(FacesContext fc) {
System.out.println("Before Rendering.");
}
};
FacesContextExImpl fc = (FacesContextExImpl) FacesContext.getCurrentInstance();
fc.addRequestListener( this.mFCListener );
}
}