将额外参数传递给 f:ajax onevent 函数 [英] Passing extra parameter to f:ajax onevent function
问题描述
在我的 JSF 2.0(在 JBoss AS 7 上)项目中,我希望在我的 ajax 提交的表单上显示一个在开始和完成阶段触发的小图标状态,让最终用户知道某些事情仍在发生.
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.
primefaces p:ajaxStatus
不是在这里很有用,因为我希望在页面的不同位置有许多不同的图标.
The primefaces p:ajaxStatus
is not useful here, as I'd like to have many different icons at different places in my page.
我在这个问题中找到了一些解决方案:如何在同一个输入中显示不同的ajax状态?",但我仍然有一个问题:为了使我的javascript函数可重用,我需要为调用提供一个额外的参数.
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.
我做了这样的事情:
<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>
并且我可以看到通过请求发送到服务器的参数extraParam",但是在我的 javascript showProgress
方法中,我无法通过唯一给定的参数恢复它.
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.
所以我的问题是:我可以通过 f:param
(或者可能是 f:attribute
或其他)?
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)?
推荐答案
将它包装在一个匿名函数中,并在其中将其作为额外参数传递.
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>
与
function showProgress(data, extraParam) {
// Use "data" argument the usual way.
// The "extraParam" argument will contain "extraValue" in above example.
}
这篇关于将额外参数传递给 f:ajax onevent 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!