我想加入一个&其中一些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).