F:在复合材料部件阿贾克斯听者停止WildFly工作10

问题描述:

我们对自己的JSF 2.2项目中使用这样的(代码已被简化为清楚起见)的复合成分:F:在复合材料部件阿贾克斯听者停止WildFly工作10

<!-- the page with the composite component inside --> 
<my:component methodListener="#{myBean.myMethod}" /> 

<!-- the composite component --> 
<cc:interface> 
    <cc:attribute name="methodListener" required="true" method-signature="void listener(javax.faces.event.AjaxBehaviorEvent)" /> 
    ... 
<cc:implementation> 
    <h:commandLink> 
     <f:ajax listener="#{cc.attrs.methodListener}" /> 
     <f:attribute name="myAttribute" value="myValue" /> 
    </h:commandLink> 
// the called method 
public void myMethod(AjaxBehaviorEvent event) 
{ 
    System.out.println("> " + event); 
} 

在Wildfly 9.0.2,当点击复合组件内部的commandLink时,myMethod被调用并且事件被定义(允许我们找回myAttribute的值)。

在Wildfly 10.1.0中,使用完全相同的代码调用myMethod,但事件参数始终为null

我们在这里做错了什么?

测试过的解决方法可能是用bean实例替换methodListener CC属性,如下面的代码。不过,这需要在我们的项目中进行大量替换,因此我们希望避免此解决方案。

<!-- the workaround composite component --> 
<cc:interface> 
    <cc:attribute name="methodBean" required="true" type="com.example.myBean" /> 
... 
<cc:implementation> 
    <h:commandLink> 
     <f:ajax listener="#{cc.attrs.methodBean.myMethod}" /> 
     <f:attribute name="myAttribute" value="myValue" /> 
    </h:commandLink> 

好吧,我没有看到BalusC this answer另一个相关的问题。我还是不明白,为什么我的代码工作的WF9并打破了WF10,但这里有一个简单的解决方案,我们在那里没有任何改变,但组件本身:

<!-- the CC xhtml --> 
<h:commandLink> 
    <f:ajax listener="#{cc.methodListener}" /> 
    <f:attribute name="myAttribute" value="myValue" /> 
</h:commandLink> 
// the CC implementation 
public void methodListener(AjaxBehaviorEvent event) 
{ 
    FacesContext context = getCurrentInstance(); 
    MethodExpression ajaxEventListener = (MethodExpression) getAttributes().get("methodListener"); 
    ajaxEventListener.invoke(context.getELContext(), new Object[] { event }); 
}