When can I call functions on a new AbstractjavaScriptComponent?

I’m using an AbstractJavaScriptComponent to put a component on the client side. (CodeMirror, if you’re curious.)

Overall, it seems to have actually worked. But I’d like to call a function on the client from the server in the constructor, like this:

 @JavaScript({
    "codemirror.js",
    "codemirror-connector.js"
    })
@StyleSheet("codemirror.css")
public class CodeMirror extends AbstractJavaScriptComponent {
    
    public CodeMirror() {
       callFunction("matchBrackets", "true");
    }

This does not work, unfortunately, and generates this (singularly unhelpful) stack trace:

Cannot call method ‘apply’ of undefinedcom.google.gwt.core.client.JavaScriptException: (TypeError)

 stack: TypeError: Cannot call method 'apply' of undefined
    at I5b (0.js:3010:26)
    at w5b (0.js:5493:106)
    at Ifc (0.js:5792:162)
    at z2b (0.js:5743:196)
    at y2b (0.js:6001:490)
    at Object.L2b [as jc]
 (0.js:6041:5159)
    at e0b (0.js:5512:106)
    at I1b (0.js:4641:91)
    at Object.L1b [as ff]
 (0.js:6041:2818)
    at t8b (0.js:5558:222): Cannot call method 'apply' of undefined
    at Unknown.I5b(0.js@26)
    at Unknown.w5b(0.js@106)
    at Unknown.Ifc(0.js@162)
    at Unknown.z2b(0.js@196)
    at Unknown.y2b(0.js@490)
    at Unknown.L2b(0.js@5159)
    at Unknown.e0b(0.js@106)
    at Unknown.I1b(0.js@91)
    at Unknown.L1b(0.js@2818)
    at Unknown.t8b(0.js@222)

I’m wondering… is it because I haven’t yet actually created the client-side connector object? If that’s the case, how do I get to say “Call this once the object actually exists”?

A possibly-related issue: for no apparent reason I am also getting:

SEVERE: Warning: your widget set seems to be built with a different version than the one used on server. Unexpected behavior may occur.

I have no idea why this should be. I’ve only ever used one version of Vaadin, version 7.1.7, and every indication is that it’s the one that I’m building my widget set with and using on the server. (NOTE: would it have killed you guys to put the reason you think the widget set is incompatible in the error message? Like, the two differing version numbers?)

Hi,

can’t really say right away what’s the reason for the exception, but in general you should be able to call functions from the constructor. In order to debug this, please enable “pretty” or “detailed” compile mode for the widgetset. This should produce a much more meaningful exception message. To do this for the vaadin plugin, go to properties → vaadin in your project and select the “javascript style” from the drop-down.

As for the version numbers, the client-side compiler simply adds its version number to the compiled widgetset and that is compared to the one that the server-side (vaadin-server jar) reports. I don’t know why the check would fail with no reason. Please double-check that you don’t have any other vaadin versions anywhere in your classpath.

Thank you so much, Teppo. That gave me what I needed to figure it out.

The problem turned out to be fairly simple and obvious: the callFunction is done on the connector, not on the underlying object. (Which should have been obvious, I guess, but I’m new to this.) All I had to do was add a pass-through, e.g.:

this.setOption = function(option, value)  { myComponent.setOption(option, value); }

Without this, of course I’d get an undefined value when trying to apply setOption: myComponent has it, but the connector didn’t. It would be nice if I didn’t have to use a connector and write that extra code, but it’s not a major hassle. And now that I understand a bit better how the connector architecture works I can manage the complications myself.

Thank you so much.

For those, who read this and are still confused there’s more information
here
and
here
. Thanks.