getWindow().executeJavaScript(javascript) NullPointerException problem

Hi everyone,

While working on an application that combines both vaadin and jQuery, i faced a problem which consists in a NullPointerException.
In the application, i created a verticalLayout and in its constructor i got the window related to the layout as following:


to execute the javascript, but the getWindow() returns a null.
It seems like the window has not been initialized, however, when i put the same instruction in a button click event handler method to execute the javascript(when i click on a button) works fine.
Do you have any ideas on how can i counter this problem? Do you have any explications that may help me solve the problem myself?
Any suggestions, or help would be highly appreciated.
Thank you in advance.

As long as your layout is not added to anything (using setContent or addComponent), it is not related to any window in particular.
You can override the attach method (don’t forget to call super) and do your initialization there as it is triggered by those 2 methods and getWindow should be defined there.

Thank you Mathias for the help, i tried the solution you suggested and it worked fine and the NullPointerException didn’t show up.
I want to select an element from the VertticalLayout through jQuery but i can’t select any element from the page, do you have any ideas?
Thanks in advance.

I have never tried.
Maybe you can add a special class name to elements in the page and have jquery look for that class.
I can’t think of other ways which would survive the release mode or changing page layout slightly…

Thank you Mathias, i really appreciated your help.
For the moment, it still not working as expected but at least i have a path to work on and make some researchs. :slight_smile: