Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 组合组件中从未调用的阶段侦听器_Java_Jsf_Jsf 2_Composite Component_Phaselistener - Fatal编程技术网

Java 组合组件中从未调用的阶段侦听器

Java 组合组件中从未调用的阶段侦听器,java,jsf,jsf-2,composite-component,phaselistener,Java,Jsf,Jsf 2,Composite Component,Phaselistener,我有一个复合组件: 及其类别: @FacesComponent(“com.example.MyComponent”) 公共类MyComponent扩展UIOutput实现NamingContainer、PhaseListener { @凌驾 公共字符串getFamily() { 返回“javax.faces.NamingContainer”; } @凌驾 公共PhaseId getPhaseId() { 返回相位ID。任何相位; } @凌驾 前期公共无效(阶段事件事件) { //做点什么。。

我有一个复合组件:


及其类别:

@FacesComponent(“com.example.MyComponent”)
公共类MyComponent扩展UIOutput实现NamingContainer、PhaseListener
{
@凌驾
公共字符串getFamily()
{
返回“javax.faces.NamingContainer”;
}
@凌驾
公共PhaseId getPhaseId()
{
返回相位ID。任何相位;
}
@凌驾
前期公共无效(阶段事件事件)
{
//做点什么。。。
}
@凌驾
公共无效后阶段(阶段事件事件)
{
//做点什么。。。
}
}
在任何情况下都不会调用
beforePhase(PhaseEvent)
afterPhase(PhaseEvent)
方法,无论是完全页面加载还是部分页面加载

我在这里注意到这个bug:,但它似乎在很久以前就被修复了

我在Java 6u33 x64上使用GlassFish 3.1.2.2。

每当
{cc}
beforePhase()
afterPhase()
方法实际需要由
UIViewRoot执行时,都会重新计算
{cc}
。此时,
{cc}
在EL范围内不可用。它仅在组件的范围内可用

如果
绑定
指向复合组件构造函数中至少一个请求范围内的变量(如下所示),那么它就可以正常工作:

public MyComponent() {
    FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("ccc", this);
}
public MyComponent() {
    FacesContext.getCurrentInstance().getViewRoot().addPhaseListener(this);
}


当然,只有当您有多个这种类型的复合组件时,这个构造才会失败

您最好寻找另一种方法:完全去掉
,只在复合组件的构造函数中使用:

public MyComponent() {
    FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("ccc", this);
}
public MyComponent() {
    FacesContext.getCurrentInstance().getViewRoot().addPhaseListener(this);
}

与具体问题无关最好使用常量,而不是硬编码
“javax.faces.NamingContainer”

每次当
beforePhase()或
afterPhase()时,都会重新计算
{cc}
的方法实际上需要由
UIViewRoot执行。此时,
{cc}
在EL范围内不可用。它仅在组件的范围内可用

如果
绑定
指向复合组件构造函数中至少一个请求范围内的变量(如下所示),那么它就可以正常工作:

public MyComponent() {
    FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("ccc", this);
}
public MyComponent() {
    FacesContext.getCurrentInstance().getViewRoot().addPhaseListener(this);
}


当然,只有当您有多个这种类型的复合组件时,这个构造才会失败

您最好寻找另一种方法:完全去掉
,只在复合组件的构造函数中使用:

public MyComponent() {
    FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("ccc", this);
}
public MyComponent() {
    FacesContext.getCurrentInstance().getViewRoot().addPhaseListener(this);
}


与具体问题无关最好使用常量而不是硬编码
“javax.faces.NamingContainer”

。。。我想我已经掌握了生命周期的知识。是的,它能用,而且足够干净。谢谢你给我额外的小费。这就是我一直在寻找的常数。啊。。。我想我已经掌握了生命周期的知识。是的,它能用,而且足够干净。谢谢你给我额外的小费。这正是我一直在寻找的常数。