传递额外的参数到f:阿贾克斯的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 号码:ajaxStatus
是没有用武之地了,因为我想有很多不同的图标,在不同的地方在我的网页。
The primefaces p:ajaxStatus
is not useful here, as I'd like to have many different icons at different places in my page.
我搜了一下这个问题的解决方案:<一href="http://stackoverflow.com/questions/7043840/jsf-2-how-show-different-ajax-status-in-same-input">How表现出相同的输入不同的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:AJAX的OnEvent
到 JavaScript方法的其它附加参数F:参数
(或者 F:属性
,或其他任何东西)
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:阿贾克斯的OnEvent功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!