AjaxBehavior在运行时添加,但AjaxBehaviorListener不调用 [英] AjaxBehavior added at runtime but AjaxBehaviorListener is not invoked

查看:245
本文介绍了AjaxBehavior在运行时添加,但AjaxBehaviorListener不调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想加入一个&其中一些Ajax行为; H:inputText的> 组件在运行。 我花了一天时间来弄清楚到底是怎么回事错的下一个code,但没有成功。

调用 initUIComponent 方法后,分量的确触发Ajax请求,还恢复正常的Ajax响应。然而,AjaxBehaviorListener永远不会被调用。什么我错过了?我使用的GlassFish 3.1.2.2的缺省mojarra实现。

 公共无效initUIComponent(的HtmlInputText C){
    FacesContext的FC = FacesContext.getCurrentInstance();

    AjaxBehavior ajaxBeh =(AjaxBehavior)fc.getApplication().createBehavior(AjaxBehavior.BEHAVIOR_ID);
    ajaxBeh.setRender(Collections.singletonList(elId1));
    ajaxBeh.setExecute(Collections.singletonList(@本));
    ajaxBeh.addAjaxBehaviorListener(新AjaxBehaviorListener(){
        @覆盖
        公共无效processAjaxBehavior(AjaxBehaviorEvent E)
                抛出AbortProcessingException {
            的System.out.println(一些正在发生的事情!);

        }
    });
    c.addClientBehavior(KEYUP,ajaxBeh);

}
 

解决方案

最后,似乎这是一个Mojarra错误。在code工作顺利,MyFaces的。 这里是相关的JIRA问题(JAVASERVERFACES-2674)。

I am trying to add some ajax behaviour in a <h:inputText> component at runtime. I spent a day to figure out what is going wrong with the next code with no success.

After invoking the initUIComponent method, the component indeed triggers ajax requests, a normal ajax response is also returned. However the AjaxBehaviorListener is never invoked. What have I missed? I use glassfish 3.1.2.2 with the default mojarra implementation.

public void initUIComponent(HtmlInputText c) {
    FacesContext fc = FacesContext.getCurrentInstance();

    AjaxBehavior ajaxBeh = (AjaxBehavior) fc.getApplication() .createBehavior(AjaxBehavior.BEHAVIOR_ID);
    ajaxBeh.setRender(Collections.singletonList("elId1"));
    ajaxBeh.setExecute(Collections.singletonList("@this"));
    ajaxBeh.addAjaxBehaviorListener(new AjaxBehaviorListener() {
        @Override
        public void processAjaxBehavior(AjaxBehaviorEvent e)
                throws AbortProcessingException {
            System.out.println("Something is happening!");

        }
    });
    c.addClientBehavior("keyup", ajaxBeh);

}

解决方案

Finally it seems that this is a Mojarra bug. The code works smoothly with MyFaces. Here is the related Jira issue (JAVASERVERFACES-2674).

这篇关于AjaxBehavior在运行时添加,但AjaxBehaviorListener不调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆