I have an BrowserFrame that displays a BI Dashboard. I would like to use iframe.contentWindow.postMessage(JSON.stringify({key: val, key2: val, ...}))
to update the data in the iframe when my user selects a value from a lookup field or other control on the page.
Should I use AbstractJavaScriptExtension to achieve this or there a better approach?
Yes, using AbstractJavaScriptExtension would be the best way, as if you pass some parameters to your function, Vaadin will escape them properly for you.
This isn’t not working. It could be that the Iframe is not submitting the event but I wanted to make sure there was not something happening on the vaadin side.
You were correct. I had a small misconfiguration. One last thing, what is the best way to communicate the event details back to the CUBA backend from the javascript event handler? Can you provide a quick code example?
For this purpose you can register JavaScriptFunction inside your extension, that would be invoked from the client side js code.
In MyExtension.java constructor add
addFunction("updateCUBA", new JavaScriptFunction() {
@Override
public void call(JSONArray arguments) throws JSONException {
// Do your stuff here
}
});
In my-extension.js code you can invoke it inside the message listener: