f:ajax onevent不适用于预定义功能,但可以与内联功能一起使用 [英] f:ajax onevent doesn't work with predefined function, but works with inline function
问题描述
我有一个< h:commandButton>
,它通过< f:ajax>
提交表单.
I have a <h:commandButton>
which submits a form by <f:ajax>
.
<h:commandButton value="Create Project" styleClass="greyishBtn submitForm">
<f:ajax execute="@form" listener="#{projectController.create}"
render=":tblProject" />
</h:commandButton>
它应该工作,但是当我尝试添加 onevent
属性时:
It works as it should be, but when I tried to add onevent
attribute like:
<f:ajax execute="@form" listener="#{projectController.create}"
onevent="createProjectEventHandler" render=":tblProject" />
已包含此JavaScript:
with this JavaScript that is already been included:
function createProjectEventHandler(data){
console.log('sth happened');
}
,然后单击按钮,然后它会重新加载页面.我看不到任何内容已提交回托管Bean,并且控制台上也没有任何内容.
and click on button, then it just reloads the page. I don't see anything has been submitted back to managed bean and nothing on console.
这是怎么引起的,我该如何解决?
How is this caused and how can I solve it?
更新:它可以通过以下方法使用:
Update: it works with the following approach:
<f:ajax execute="@form" listener="#{projectController.create}"
onevent="function(data) {console.log('aaa');}" render=":tblProject" />
为什么会这样?基于有关f:ajax事件的Java EE 6教程, onevent
属性应支持JavaScript函数名称.
Why is that so? Based on the Java EE 6 tutorial on f:ajax events, the onevent
attribute should support a JavaScript function name.
推荐答案
我在Netbeans中遇到了同样的问题.
I had the same issue in Netbeans.
当我在Netbeans中创建JSF页面时,它生成了 xmlns:f ="http://xmlns.jcp.org/jsf/core"
作为XML名称空间URI.但这是JSF 2.2特有的,而我实际上是在使用JSF 2.0/2.1.
When I created my JSF page in Netbeans, it generated xmlns:f="http://xmlns.jcp.org/jsf/core"
as XML namespace URI. But that was JSF 2.2 specific while I was actually using JSF 2.0/2.1.
当我将XML名称空间URI更改为 xmlns:f ="http://java.sun.com/jsf/core"
时,它对我有用.
When I changed the XML namespace URI to xmlns:f="http://java.sun.com/jsf/core"
, then it worked for me.
这篇关于f:ajax onevent不适用于预定义功能,但可以与内联功能一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!