如何使用< a4j:jsFunction>< a4j:actionparam> [英] How to use <a4j:jsFunction><a4j:actionparam>
本文介绍了如何使用< a4j:jsFunction>< a4j:actionparam>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用:
<script type="text/javascript">
function myfunc() {
var param = 4;
alert("OK");
}
</script>
我这样调用函数:
<a4j:jsFunction name="myfunc">
<a4j:actionparam name="param" assignTo="#{MyBean.myfield}"/>
</a4j:jsFunction>
但是它不起作用.可能是什么原因?
But it does not work. In what may be the reason?
推荐答案
您误解了<a4j:jsFunction>
的目的.它会自动生成一个JavaScript函数,然后您可以从视图中的任何JavaScript代码中调用该函数.
You misunderstood the purpose of <a4j:jsFunction>
. It autogenerates a JavaScript function which you can then call from any JavaScript code in your view.
您的示例
<a4j:jsFunction name="myfunc">
<a4j:actionparam name="param" assignTo="#{MyBean.myfield}"/>
</a4j:jsFunction>
将自动生成以下功能
<script>
function myfunc(param) {
// Here some specific JSF Ajax script which assigns "param"
// to a managed bean property #{MyBean.myfield}
}
</script>
您不需要需要自己定义.您只需要自己从其他地方的一些JavaScript代码中调用即可.例如,
You do not need to define it yourself. You only need to invoke it yourself from some JavaScript code elsewhere. For example,
<span onclick="myfunc(4)">click here to set 4 in MyBean.myfield</span>
或
<script>
function someOtherFunction() {
var param = 4;
myfunc(param);
}
</script>
依次使用
<span onclick="someOtherFunction()">click here to call someOtherFunction() which will in turn set 4 in MyBean.myfield</span>
另请参见:
-
<a4j:jsFunction>
展示示例 <a4j:jsFunction>
component reference<a4j:jsFunction>
showcase example
See also:
这篇关于如何使用< a4j:jsFunction>< a4j:actionparam>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文