voyent
Ice.onAsynchronousReceive(id, callback)  XML
Forum Index -> General Help
Author Message
venu_dvmr

Joined: 30/Sep/2008 00:00:00
Messages: 58
Offline


How does this work Ice.onAsynchronousReceive(id, callback)? Can some one provide a sample or an example. when I try the below code it throws as js error in 1E7 "Object does not support this property or method". I did not test it in other browsers.

ICEfaces 1.8.0
Build number: 12
Revision: 18727



Code:
<body id="document:body">
 <script type="text/javascript">
 Ice.onAsynchronousReceive('document:body', function() {
 alert('onAsynchronousReceive Callback!');
 });
 </script>
mircea.toma

Joined: 10/Feb/2005 00:00:00
Messages: 323
Offline


It looks like I mistyped the function name. The function name is Ice.onAsyncronousReceive, without the 'h'. I created a JIRA case for this -- http://jira.icefaces.org/browse/ICE-4348 . In the mean time you can still use the function the way is named currently.
[Email]
venu_dvmr

Joined: 30/Sep/2008 00:00:00
Messages: 58
Offline


Thank you it works now. For those who are using use it with prototype http://www.prototypejs.org/api/utility/try-these so hat it can work even after the bug fix.
ENDelt260

Joined: 17/Jun/2009 00:00:00
Messages: 16
Offline


Where is the documentation for this? So far all I have stumbled upon is this... which doesn't really tell me much other than it exists.

Using: Icefaces 1.8.2, JBoss Seam 2.2.0.GA, Weblogic 10.3
gus315

Joined: 14/Nov/2006 00:00:00
Messages: 158
Offline


venu_dvmr wrote:

Code:
<body id="document:body">
 <script type="text/javascript">
 Ice.onAsynchronousReceive('document:body', function() {
 alert('onAsynchronousReceive Callback!');
 });
 </script>
 

Hi Venu_dvmr, could you please give some code snippets to show how to call the "Ice.onAsynchronousReceive..." method from a jsf page. Thank you very much in advance.
karinchen

Joined: 21/Nov/2008 00:00:00
Messages: 14
Offline


Hi!

Looking at the method's signature ( Ice.onAsynchronousReceive(id, callback) ), I would expect to be possible to use it for a specific JSF element (like a commandLink) on my page, not just the entire body.
In docs it says that 'id' is "the identifier of an element that is the parent or the child of the element owning the bridge instance (most of the time is the `body' element)" - ok, just most of the time :)

However, the callback appears to be called for every JSF action, no matter what is passed in as id.

I'll try to explain what we're doing:

What we want is to execute a Javascript snippet on click of a link (plain HTML link) and the HTML link also triggers a JSF action (by triggering a click event on a JSF commandLink with a specific id - this is done by jQuery); however, it's important that the javascript snippet is executed *after* the server action has finished.

The HTML link has therefore an on-click handler which does like:

Code:
jQuery(JSFcommandLinkId).trigger('click'); 
 // this causes the server action to be done


Code:
 <h:commandLink id="JSFcommandLinkId" action="#{myBean.doSomethingWhichMustBeReadyBeforeJavascriptSnippet}/>


and we're calling
Code:
Ice.onAsynchronousReceive("JSFcommandLinkId", globalCallBackHandler);


would call the callback on each JSF action on the page. We're using Icefaces 1.8.2, however, the page has JSF tags. Icefaces is mainly used as the view-handler of our pages which are Facelets pages from some portlets deployed in Liferay.

Any help appreciated!
Karina

PS. I know it sounds like a crazy mix here, I feel we're approaching it wrong - all we want is the JSF action of a commandLink to be ready before another javascript is called.
mircea.toma

Joined: 10/Feb/2005 00:00:00
Messages: 323
Offline


The callback registered with Ice.onAsynchronousReceive will be called only when an asynchronous update (pushed update) is sent to the browser. You will have to wire the same callback with Ice.onSendReceive as well to catch the updates that are applied during user interaction.

Unfortunately both registration functions do not provide the context in which they execute, such as what elements are updated.

Maybe using JavascriptContext API is more suited for the use case you have. The API can be called from a bean and it allows you to inject Javascript code into the browser, dynamically. See http://www.icefaces.org/docs/v1_8_2/javadocs/icefaces/api/com/icesoft/faces/context/effects/JavascriptContext.html#addJavascriptCall(javax.faces.context.FacesContext,%20java.lang.String)
[Email]
karinchen

Joined: 21/Nov/2008 00:00:00
Messages: 14
Offline


Hi Mircea!

Thank you very much, this actually appears to be working fine for our case!

One question: The second parameter which is a String will be output to the generated code just as it is, like:

Code:
JavascriptContext.addJavascriptCall(FacesContext.getCurrentInstance(), "add(3,4)");


means probably:
Code:
 <script type="text/javascript">
 add(3,4);
 </script>


If you want to have several JS methods, then I noticed you have to have like:
Code:
JavascriptContext.addJavascriptCall(FacesContext.getCurrentInstance(), "add(3,4)[b];[/b]");

Code:
JavascriptContext.addJavascriptCall(FacesContext.getCurrentInstance(), "add(5,6)");



So you have to append a colon after each call besides the last.

Thank you very much for your help!
Karina
 
Forum Index -> General Help
Go to:   
Powered by JForum 2.1.7ice © JForum Team