Posted by Claudiu on 15th January 2010
n/a

A4j:jsFunction on page load

Problem

You need to send some data to the server on page access. One way to do this is by calling an a4j:jsFunction with the appropriate parameters.
The problem is that you have to call this function after the page has fully loaded.

Solution

Use the jQuery(document).ready for this.
If you call the function too early in an embedded Javascript code it will try to call the @Create method of the bean once again. That second call will probably throw some exceptions which are hard to detect.
Took me some time to figure this out since the console pointed me to the @Create method.

Update

After working with seam remoting component I figured out the answer to this behavior. Seam remoting behaves in the same way if used with the most basic settings. It considers the bean to be stateless. After pointing it to use the current conversation everything works ok. The a4j:jsFunction probably doesn’t have time to set it’s conversation status before being called in an inline javascript code. Hence the repeated call to the @Create method.

Comments are closed!