javascript 将额外参数传递给 f:ajax onevent 函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9067685/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Passing extra parameter to f:ajax onevent function
提问by Xavier Portebois
In my JSF 2.0(on JBoss AS 7) project, I would like on my ajax submitted forms to display a little icon status triggered on begin and complete phases, to let the end user know that something is still happening.
在我的JSF 2.0(在JBoss AS 7 上)项目中,我希望在我的 ajax 提交表单上显示在开始和完成阶段触发的小图标状态,让最终用户知道某些事情仍在发生。
The primefaces p:ajaxStatus
is not useful here, as I'd like to have many different icons at different places in my page.
该primefacesp:ajaxStatus
是没有用在这里,因为我想有在我的网页不同的地方很多不同的图标。
I found a bit of the solution in this question: "How show different ajax status in same input?", but I still have a problem: in order to make my javascript function reusable, I need to provide an extra parameter to the call.
我在这个问题中找到了一些解决方案:“如何在同一输入中显示不同的 ajax 状态?”,但我仍然有一个问题:为了使我的 javascript 函数可重用,我需要为调用提供一个额外的参数。
I did something like this:
我做了这样的事情:
<h:commandLink value="do something boy!">
<f:ajax render="@form" execute="@form" listener="#{myBean.doStuff}"
onevent="showProgress" />
<f:param name="extraParam" value="extraValue" />
</h:commandLink>
and I can see the parameter "extraParam" sent to the server through the request, but in my javascript showProgress
method I cannot recover it through the only given parameter.
我可以看到通过请求发送到服务器的参数“extraParam”,但在我的 javascriptshowProgress
方法中,我无法通过唯一给定的参数恢复它。
So my questions is: can I provide to my f:ajax onevent
javascript method an additionnal parameter through f:param
(or maybe f:attribute
, or anything else)?
所以我的问题是:我可以f:ajax onevent
通过f:param
(或者可能f:attribute
,或其他任何东西)向我的javascript 方法提供一个附加参数吗?
回答by BalusC
Wrap it in an anonymous function wherein you pass it as extra argument.
将它包装在一个匿名函数中,在其中将它作为额外的参数传递。
<h:commandLink value="do something boy!">
<f:ajax render="@form" execute="@form" listener="#{myBean.doStuff}"
onevent="function(data) { showProgress(data, 'extraValue') }" />
</h:commandLink>
with
和
function showProgress(data, extraParam) {
// Use "data" argument the usual way.
// The "extraParam" argument will contain "extraValue" in above example.
}