RAP 1.5 - Passing JSON to a custom widget's javaScript [message #1019444] |
Fri, 15 March 2013 17:50 |
Jay Hamilton Messages: 26 Registered: October 2011 |
Junior Member |
|
|
I have succesfully made use of the custom widget approach for integrating with JQuery using Ralf Sternberg's carousel example. However, I am trying to pass in json data to the jquery FLOT library and have not had any success. I have a help js function called that receives a string and then uses the jquery.parseJSON function. I cannot tell what is landing in the helper script function. Constructing the string and then parsing it within the helper function works with no isssue. It is just the string passed in from the Brower.evaluate function does not seem to work. Any thoughts?
Here is my code snippet:
....
browser.addProgressListener(new ProgressListener() {
/**
*
*/
private static final long serialVersionUID = 24362258291398084L;
public void completed(ProgressEvent event) {
loaded = true;
updateData("[{\"label\":\"Series1\",\"data\":10},{\"label\":\"Series2\",\"data\":15},{\"label\":\"Series3\",\"data\":315}]");
flushQueue();
}
public void changed(ProgressEvent event) {
}
});
The updateData function
public void updateData(String data) {
internalAddItem(data);
if (loaded) {
String script = "getData('" + data + "');";
browser.evaluate(script);
} else {
addItemToQueue(data);
}
}
now my javascript helper function:
var getData = function(data) {
/*this works ---> var data = '[{"label": "Series1", "data": 10},{"label": "Series2", "data": 15},{"label": "Series3", "data": 315}]';*/
return = $.parseJSON(data);
}
|
|
|
|
|
|
|
Re: RAP 1.5 - Passing JSON to a custom widget's javaScript [message #1027693 is a reply to message #1027128] |
Wed, 27 March 2013 09:26 |
Tim Buschtoens Messages: 396 Registered: July 2009 |
Senior Member |
|
|
Hi.
> Is there any drawback by using
> browser.evaluate() routine?
Compared to Remote API, there are a few drawbacks.
- It's not possible to group multiple operations, potentially causing
more traffic and taking longer to load. We noticed that when we
implemented the CKEditor based on Browser[1]. With Remote API, all
operations are rendered within the same response.
- You have to wait until the Browser widget is ready before you can use
Browser#evaluate(). Look at evalOnReady() in [1].
- Browser#evaluate() works differently when using the JEE operation
mode, it no longer blocks execution. Look at getText in [2]. While you
can not use Remote API to block execution either (it's more comparable
to BrowserFunctions), it's way more efficient keeping the server updated
using the JavaScript API[3].
Basically, the more data you have to keep in sync between client and
server, the less efficient it gets. That's why the GMaps Widget[4] is a
good match for the Browser Widget, but the CKEditor less so.
I hope that answers your question. Of course, the upside of using the
Browser widget is that it can be made compatible with SWT, like in the
GMaps widget. There is currently no way to use the Remote API with SWT.
Greetings,
Tim
[1]
https://github.com/eclipsesource/rap-ckeditor/blob/streams/1.5/com.eclipsesource.widgets.ckeditor/src/com/eclipsesource/widgets/ckeditor/CKEditor.java
[2]
https://github.com/eclipsesource/rap-ckeditor/blob/JEE/com.eclipsesource.widgets.ckeditor/src/com/eclipsesource/widgets/ckeditor/CKEditor.java
[3]
http://download.eclipse.org/rt/rap/doc/2.0/guide/reference/jsdoc/symbols/rap.html#.getRemoteObject
[4] https://github.com/eclipsesource/rap-gmap
--
Tim Buschtöns
Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/
Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
|
|
|
|
Powered by
FUDForum. Page generated in 0.03605 seconds