2017-04-18 61 views
0

我們對自己的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> 

回答

0

好吧,我沒有看到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 }); 
}