【问题标题】:f:ajax listener in composite component stopped working in WildFly 10复合组件中的 f:ajax 侦听器在 WildFly 10 中停止工作
【发布时间】: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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-17
      • 2012-09-17
      • 1970-01-01
      • 2012-04-08
      相关资源
      最近更新 更多