Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » RAP 1.5 - Passing JSON to a custom widget's javaScript(Is it possible to pass a Java String of a JSON format into Browser.evaluate())
RAP 1.5 - Passing JSON to a custom widget's javaScript [message #1019444] Fri, 15 March 2013 17:50 Go to next message
Jay Hamilton is currently offline Jay HamiltonFriend
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);
	
}


icon14.gif  Re: RAP 1.5 - Passing JSON to a custom widget's javaScript [message #1019711 is a reply to message #1019444] Sat, 16 March 2013 12:38 Go to previous messageGo to next message
Jay Hamilton is currently offline Jay HamiltonFriend
Messages: 26
Registered: October 2011
Junior Member
False alarm. JSON string passing from a RAP custom widget to a helper javascript function via Browser.evaluate() does work. My problem was actually related to not fully implementing Ralf's example. My JSON string is used to set the data for a FLOT chart. In order to display the chart I needed to render it independent of setting the data. So an additional javascript helper function was created to render the chart after having passed in the JSON string.

[Updated on: Sat, 16 March 2013 12:41]

Report message to a moderator

Re: RAP 1.5 - Passing JSON to a custom widget's javaScript [message #1020543 is a reply to message #1019711] Mon, 18 March 2013 12:16 Go to previous messageGo to next message
Ralf Sternberg is currently offline Ralf SternbergFriend
Messages: 1313
Registered: July 2009
Senior Member

Jay, good to know that it works. If you're creating a brand new widget,
it may be worth to consider the new RemoteObject API [1] instead of
building your widget on Browser.evaluate. This API lets you build your
widget directly on top of the new JSON protocol.

The problem with Browser.evaluate is that it relies on a result and
therefore has to be performed synchronously, which is an exception to
the normal request processing.

Regards,
Ralf

[1] http://eclipse.org/rap/noteworthy/2.0/

--
Ralf Sternberg

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: RAP 1.5 - Passing JSON to a custom widget's javaScript [message #1020835 is a reply to message #1020543] Tue, 19 March 2013 02:25 Go to previous messageGo to next message
Jay Hamilton is currently offline Jay HamiltonFriend
Messages: 26
Registered: October 2011
Junior Member
Thanks Ralf. I will look into that. In the meantime I have another issue that i will post on the Forum related to the layout of the custom widget within a view.
Re: RAP 1.5 - Passing JSON to a custom widget's javaScript [message #1027128 is a reply to message #1020543] Tue, 26 March 2013 15:32 Go to previous messageGo to next message
Ronald So is currently offline Ronald SoFriend
Messages: 198
Registered: April 2011
Senior Member
Hi Ralf,

We are using RAP 1.5.1 so we are pretty much out of luck using the new RemoteObject infrastructure right? Is there any drawback by using browser.evaluate() routine?

Thanks!

Ronald
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 Go to previous messageGo to next message
Tim Buschtoens is currently offline Tim BuschtoensFriend
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/
Re: RAP 1.5 - Passing JSON to a custom widget's javaScript [message #1028003 is a reply to message #1027693] Wed, 27 March 2013 17:56 Go to previous message
Ronald So is currently offline Ronald SoFriend
Messages: 198
Registered: April 2011
Senior Member
Yes Tim thank you so much for the additional information!
Previous Topic:org.json package missing from build
Next Topic:Validations
Goto Forum:
  


Current Time: Fri Mar 29 08:33:16 GMT 2024

Powered by FUDForum. Page generated in 0.08080 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top