Custom widget and $(document).ready


I’m creating a custom widget using a public javascript image gallery based on jQuery. I’ve tried three and all of them include someting like this to bootstrap the gallery

$(document).ready(function() {

After a few tests I’ve found the problem is that when document is ready, $(javascriptSelector) is void, it has not elements inside, and for that reason bootstrap fails. It seems content load is deferred. If I put a button elsewhere to execute bootstrap, it works.
Ive tried with a setTimeout() delay execution. While $(javascriptSelector).size==0, it delays execution. I think it’s not a safe way to know if the page is fully loaded. How can I be sure of that?


I solved it by using JSNI. After loadin the gallery content I call the bootstrap function with a native function.

would you please post how you have created /compiled the custom widget. I want to use JSNI, and when I call the native function I get the following error

here is my other post with the problem

at com.vaadin.event.EventRouter.fireEvent(
at com.vaadin.ui.AbstractComponent.fireEvent(
at com.vaadin.ui.Button.fireClick(
at com.vaadin.ui.Button$
... 76 more
Caused by: java.lang.UnsatisfiedLinkError: com.example.vaadinsample.VaadinsampleApplication.alert(Ljava/lang/String;)V
at com.example.vaadinsample.VaadinsampleApplication.alert(Native Method)
at com.example.vaadinsample.VaadinsampleApplication$2.buttonClick(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at com.vaadin.event.ListenerMethod.receiveEvent(
... 80 more 

Please avoid multiple posting - for the UnsatisfiedLinkException, see
this thread