I am trying to make call to JSF functions in my app more dynamic. Instead of static way of writing callback functions to oncomplete
event by hand, I wish to send a callback function as a parameter and make it's invoke inside oncomplete
event of the function. Here's an example:
<script type="text/javascript">
myFunc('myParamValue', function(){
doThis();
andDoThis();
});
</script>
<a4j:jsFunction name="myFunc" actionListener="#{...}" data="" oncomplete="">
<f:param name="myParam" />
<f:param name="callback" />
</a4j:jsFunction>
I wish to ask if that would be possible by using data
attribute of a4j:jsFunction
? Something like this:
...
data="#{myBean.callback}"
oncomplete="if (typeof window[event.data] == 'function') window[event.data]();"
...
Try something like this:
// Page
<a4j:jsFunction name="callScript" data="#{bean.someProperty1}"
reRender="someComponent"
oncomplete="execute(data.callback)">
<a4j:actionparam name="something" assignTo="#{bean.something}"/>
<a4j:actionparam name="callback" assignTo="#{bean.callback}"/>
</a4j:jsFunction>
// JS
function testFunction() {
alert("It works!");
}
function execute(funcName) {
//is no namespace use window
window[funcName]();
}
//call
callScript("param1", "testFunction");
Try this:
<a4j:jsFunction name="callScript" data=".."
reRender="someComponent"
oncomplete="foo(data,request)">
<a4j:actionparam name="something" assignTo="#{bean.something}"/>
<a4j:actionparam name="callback" />
and js
function foo(data,request) {
var callback =request.options.parameters.callback ;
callback(data);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With