如何以编程方式或动态地将 ajax 侦听器添加到 JSF 2 组件?
如何以编程方式或动态地将 ajax 侦听器添加到 JSF 2 组件?
我尝试过:
...
FacesContext facesContext = FacesContext.getCurrentInstance();
AjaxBehavior dragStart = (AjaxBehavior)facesContext.getApplication().createBehavior(AjaxBehavior.BEHAVIOR_ID);
dragStart.addAjaxBehaviorListener(new DragEnterListener());
dragStart.setTransient(true);
component.addClientBehavior("dragstart", dragStart);
...
public class DragEnterListener implements AjaxBehaviorListener {
@Override
public void processAjaxBehavior(AjaxBehaviorEvent event) throws AbortProcessingException {
System.out.println("AjaxListener CALLED!!! ");
}
}
但这不起作用。在页面中我遇到了这个 JS 异常:
serverError: class java.lang.IllegalStateException
cz.boza.formcreator.FormModel$DragEnterListener
我在 RichFaces 中找到了这个示例: http://community.jboss.org/message/611571
但是在 AjaxBehavior 类中的普通 JSF 2 中不存在
addAjaxBehaviorListener(MethodExpression methodExpression)
,只是
addAjaxBehaviorListener(ValueExpression valueExpression)
我已经尝试解决这个问题很多天了。
请帮忙。
非常感谢。
How to programmatically or dynamically add ajax listener to JSF 2 component?
I tried:
...
FacesContext facesContext = FacesContext.getCurrentInstance();
AjaxBehavior dragStart = (AjaxBehavior)facesContext.getApplication().createBehavior(AjaxBehavior.BEHAVIOR_ID);
dragStart.addAjaxBehaviorListener(new DragEnterListener());
dragStart.setTransient(true);
component.addClientBehavior("dragstart", dragStart);
...
public class DragEnterListener implements AjaxBehaviorListener {
@Override
public void processAjaxBehavior(AjaxBehaviorEvent event) throws AbortProcessingException {
System.out.println("AjaxListener CALLED!!! ");
}
}
But thid doesn't work. In page I've got this JS exception:
serverError: class java.lang.IllegalStateException
cz.boza.formcreator.FormModel$DragEnterListener
I found this example in RichFaces:
http://community.jboss.org/message/611571
But in plain JSF 2 in AjaxBehavior class there is no
addAjaxBehaviorListener(MethodExpression methodExpression)
there is only
addAjaxBehaviorListener(ValueExpression valueExpression)
I'm trying to solve this for many days.
Please help.
Thank you very much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,所以我做了更多研究,发现如果我不想添加ajax侦听器的
组件
也被动态添加(来自java - 就像parant.getChildren().add(组件)
)进入页面,一切正常。但是,如果我不想添加ajax侦听器的< /code>) 进入页面,引发上述奇怪的异常:
组件
是静态添加的(在jsp中 - 就像我将尝试在 JSF 论坛中提出这个问题。可能这是 Mojara 中的一个错误。
OK, so I made more research and found that if the
component
in which I wan't to add ajax listener is also added dynamically (from java - likeparant.getChildren().add(component)
) into the page, everything works fine.But if
component
in which I wan't to add ajax listener is is added statically (in jsp - like<h:panelGroup binding="#{bean.component}">
) into the page, aforementioned weird exception is thrown:I will try to ask this question in JSF forum. May be it's a bug in Mojara.