Send JSF a4j callback: jsFunction oncomplete event

I am trying to make the JSF function call in my application more dynamic. Instead of the static way of writing the callback functions to the oncomplete event manually, I want to send the callback function as a parameter and make it call inside the oncomplete event of the function . Here is 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 want to ask if this is possible using the data a4j:jsFunction ? Something like that:

 ... data="#{myBean.callback}" oncomplete="if (typeof window[event.data] == 'function') window[event.data]();" ... 
+8
javascript callback jsf-2 richfaces ajax4jsf
source share
2 answers

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"); 
+6
source share

Try the following:

 <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); } 
+2
source share

All Articles