AbstractJavaScriptComponent.getState() can't be used for javascript writing

Hello all,

Following the article at : http://morevaadin.com/content/integrating-html-and-javascript-part-2/, I happily display a javascript component. I can also send values from Java to javascript using getState().
But I can’t achieve to get values from javascript to java.

I was naively thinking that the bean is both way synchronized and that this piece of code could get me back some info from javascript :

    this.onStateChange = function() {

        // Reading is working
        myobject.width = this.getState().canvasWidth;
        // Writing is not working. This value will never make its way to java-side
        this.getState().canvasWidth = myobject2.width;

Am I wrong ? Do I have to implement a specific function to send back the data ?

Regards
Sebastien

Component state can only be used to send data from the server to the client.
To get an event (or data) from the Javascript client to the server you should use RPCs (
Vaadin 7 Wiki UsingJavascript/Using RPC from Javascript
).
When you’re on the wiki you should have a look around in the Custom Widgets and the Using Javascript section if you didn’t already. There is also a simpler way to use RPCs from JS.

Thanks for this information. I missed the “simpler way”, and will try to use that.

What I still can’f figure out is how I can get back data on java-side from javascript-side.

Simple-RPC
method shows how to call a javascript function from java and how to call a java function from javascript part. But how can I call a javascript function that gets me a value back ? Lets imagine the javascript side has made some computation, and at some point in the java side I want to get that value.

Is there an easy way to do so ?

Regards
Sebastien

There isn’t really something like a RPC which returns a value but you could do it this way:

Server --triggerProcessingRPC–> CLient
to trigger the processing. when the client is finisched he then just triggers another RPC back to the server:
Client --passResultsToServerRPC–>Server