【发布时间】:2017-09-14 10:05:37
【问题描述】:
我们在 JSF 2.2 项目中有一个这样使用的复合组件(为了清楚起见,代码已被简化):
<!-- 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>
【问题讨论】:
标签: jsf-2.2 composite-component wildfly-10