Vaadin and JSON

Hi,

I am really new to Vaadin, and still learning the stuff.

I want to know how to achieve:
step 1. Send request to GET JSON responses from the remote server at http://website/something.
step 2. Parse json responses and display on the browser.

I was reading UIDL, and it seems relevant. But the information in the book is not enough for me to understand how to implement it, and i cant find any sample or tutorial regarding to this. So could you please provide me some sample codes or hints to show how to implement step1 and 2?

Many Thanks,
Jay

Hi,

You can ignore the UIDL in this problem. It is JSON indeed, but it is just used to communicate between Vaadin server and the the client side engine. If you need to communicate to remote service it doesn’t help you a bit.

Doing this in completely on the server side is the Vaadin way of doing things and also real simple. Below is an example how to write our blog’s RSS feed to sysout. It is easy to adapt to JSON too. You’ll most likely want to download some of the various JSON libraries from http://www.json.org/ to help with parsing. Rest of the process is just some plain Vaadin development.


            URL myservice = new URL("http://vaadin.com/blog/-/blogs/rss");
            InputStream openStream = myservice.openStream();
            BufferedReader bufferedReader = new BufferedReader(
                    new InputStreamReader(openStream));
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                System.out.println(line);
            }

cheers,
matti