在运行时添加了AjaxBehavior,但未调用AjaxBehaviorListener

时间:2013-03-08 17:00:43

标签: java ajax jsf

我试图在运行时在<h:inputText>组件中添加一些ajax行为。 我花了一天的时间来弄清楚下一个代码出了什么问题但没有成功。

在调用initUIComponent方法之后,组件确实触发了ajax请求,还返回了正常的ajax响应。但是从不调用AjaxBehaviorListener。我错过了什么?我使用glassfish 3.1.2.2和默认的mojarra实现。

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);

}

1 个答案:

答案 0 :(得分:0)

最后看来这是一个Mojarra bug。代码与MyFaces一起顺利运行。 Here是相关的Jira问题(JAVASERVERFACES-2674)。