{"id":2917,"date":"2006-06-04T14:07:13","date_gmt":"2006-06-04T13:07:13","guid":{"rendered":"http:\/\/jelmer.jteam.nl\/?p=4"},"modified":"2006-06-04T14:07:13","modified_gmt":"2006-06-04T13:07:13","slug":"google-webtoolkit-remoting","status":"publish","type":"post","link":"https:\/\/trifork.nl\/blog\/google-webtoolkit-remoting\/","title":{"rendered":"Google WebToolkit remoting"},"content":{"rendered":"<p>Last week I started playing around with the <a href=\"http:\/\/code.google.com\/webtoolkit\/\">google webtoolkit<\/a> an Ajax framework that allows software engineers to develop complex ajax web interfaces in java rather than javascript.<\/p>\n<p>I found the  google webtoolkit not without it&#8217;s limitations,  most noteably it is very hard to style \/ layout pages compared to jsp templates etc.  But I do think it has potential for certain types  of  applications. While I struggled with other component based frameworks such as jsf, tapestry and wicket GWT was really easy to get into even though the documentation is currently still lacking and without compare to that offered by the aformentioned frameworks.<\/p>\n<p>GWT comes with its own rpc framework.  I&#8217;ll give you an example of how this works<\/p>\n<p>You start out by defining your service interface<\/p>\n<p><code><br \/>\npublic interface HelloService extends RemoteService {<br \/>\nString sayHello(String name);<br \/>\n}<br \/>\n<\/code><\/p>\n<p>Service interfaces should allways extend from the RemoteService  marker interface. Then you create an asychronous companion interface<\/p>\n<p><code><br \/>\npublic interface HelloServiceAsync {<br \/>\nvoid sayHello(String name, AsyncCallback callback);<br \/>\n}<br \/>\n<\/code><\/p>\n<p>The relationship between a service interface and its asynchronous counterpart is straightforward:<br \/>\nIf a service interface is called com.example.HelloService , then the async interface must be called com.example.HelloServiceAsync. The async interface must be in the same package and have the same name, but with the suffix Async.<\/p>\n<p>I actually don&#8217;t like having to repeat myself like this but i suppose it can&#8217;t be helped,  eventually the code will get translated to javascript and as I understand it all javascript code runs within the context of a single thread. You can&#8217;t have a method blocking for 5 seconds while waiting for a response from the server because it would effectively make your application nonresponsive. If you ever played around with <a href=\"http:\/\/getahead.ltd.uk\/dwr\/\">DWR<\/a> you should be familiar with this pattern.<\/p>\n<p>Implementations of the remote interface extend from RemoteServiceServlet which is a thin layer on top of HttpServlet. and takes care of serializing \/ deserializing arguments and response objects.<\/p>\n<p><code><br \/>\npublic class HelloServiceImpl extends RemoteServiceServlet implements HelloService {<br \/>\npublic String sayHello(String name) {<br \/>\nreturn \"hello \" + name;<br \/>\n}<br \/>\n}<br \/>\n<\/code><\/p>\n<p>Once you have this it is very simple to write a simple client.<\/p>\n<p><code><br \/>\npublic class Hello implements EntryPoint {<br \/>\nprivate HelloServiceAsync helloService;<\/code><\/p>\n<p>public void onModuleLoad() {<br \/>\nhelloService = (HelloServiceAsync) GWT.create(HelloService.class);<br \/>\nServiceDefTarget endpoint = (ServiceDefTarget) helloService;<br \/>\nendpoint.setServiceEntryPoint(&#8220;\/helloservice&#8221;);<\/p>\n<p>HorizontalPanel buttonPanel = new HorizontalPanel();<br \/>\nbuttonPanel.add(new Button(&#8220;Say hello to jelmer&#8221;, new ClickListener() {<br \/>\npublic void onClick(Widget sender) {<br \/>\nhelloService.sayHello(&#8220;jelmer&#8221;,  new AsyncCallback() {<br \/>\npublic void onSuccess(Object result) {<br \/>\nString message = (String) result;<\/p>\n<p>Window.alert(message);<br \/>\n}<br \/>\npublic void onFailure(Throwable caught) {<br \/>\n}<br \/>\n});<br \/>\n}<br \/>\n}));<br \/>\nRootPanel.get().add(buttonPanel);<br \/>\n}<br \/>\n}<br \/>\nThis will add a button to your page. when pressed it will call sayHello on the remote interface and display the resulting message in a javascript alert box.<\/p>\n<p>Overall i turned out to be pretty easy and painless to create some (relatively) sophisticated functionality. The resulting code is very clean, strongly typed and you can use you favorite java ide to write it, so you have autocompletion and all that goodness available to you<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last week I started playing around with the google webtoolkit an Ajax framework that allows software engineers to develop complex ajax web interfaces in java rather than javascript. I found the google webtoolkit not without it&#8217;s limitations, most noteably it is very hard to style \/ layout pages compared to jsp templates etc. But I [&hellip;]<\/p>\n","protected":false},"author":58,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"content-type":"","footnotes":""},"categories":[31],"tags":[],"class_list":["post-2917","post","type-post","status-publish","format-standard","hentry","category-java"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Google WebToolkit remoting - Trifork Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/trifork.nl\/blog\/google-webtoolkit-remoting\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Google WebToolkit remoting - Trifork Blog\" \/>\n<meta property=\"og:description\" content=\"Last week I started playing around with the google webtoolkit an Ajax framework that allows software engineers to develop complex ajax web interfaces in java rather than javascript. I found the google webtoolkit not without it&#8217;s limitations, most noteably it is very hard to style \/ layout pages compared to jsp templates etc. But I [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/trifork.nl\/blog\/google-webtoolkit-remoting\/\" \/>\n<meta property=\"og:site_name\" content=\"Trifork Blog\" \/>\n<meta property=\"article:published_time\" content=\"2006-06-04T13:07:13+00:00\" \/>\n<meta name=\"author\" content=\"Jelmer Kuperus\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jelmer Kuperus\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/trifork.nl\/blog\/google-webtoolkit-remoting\/\",\"url\":\"https:\/\/trifork.nl\/blog\/google-webtoolkit-remoting\/\",\"name\":\"Google WebToolkit remoting - Trifork Blog\",\"isPartOf\":{\"@id\":\"https:\/\/trifork.nl\/blog\/#website\"},\"datePublished\":\"2006-06-04T13:07:13+00:00\",\"author\":{\"@id\":\"https:\/\/trifork.nl\/blog\/#\/schema\/person\/c0ee9f25744015bf661fee1b797341f2\"},\"breadcrumb\":{\"@id\":\"https:\/\/trifork.nl\/blog\/google-webtoolkit-remoting\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/trifork.nl\/blog\/google-webtoolkit-remoting\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/trifork.nl\/blog\/google-webtoolkit-remoting\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/trifork.nl\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Google WebToolkit remoting\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/trifork.nl\/blog\/#website\",\"url\":\"https:\/\/trifork.nl\/blog\/\",\"name\":\"Trifork Blog\",\"description\":\"Keep updated on the technical solutions Trifork is working on!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/trifork.nl\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/trifork.nl\/blog\/#\/schema\/person\/c0ee9f25744015bf661fee1b797341f2\",\"name\":\"Jelmer Kuperus\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/trifork.nl\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/fff87cf8073c776ffcbe26326f713998?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/fff87cf8073c776ffcbe26326f713998?s=96&d=mm&r=g\",\"caption\":\"Jelmer Kuperus\"},\"sameAs\":[\"http:\/\/www.dutchworks.nl\"],\"url\":\"https:\/\/trifork.nl\/blog\/author\/jelmer\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Google WebToolkit remoting - Trifork Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/trifork.nl\/blog\/google-webtoolkit-remoting\/","og_locale":"en_US","og_type":"article","og_title":"Google WebToolkit remoting - Trifork Blog","og_description":"Last week I started playing around with the google webtoolkit an Ajax framework that allows software engineers to develop complex ajax web interfaces in java rather than javascript. I found the google webtoolkit not without it&#8217;s limitations, most noteably it is very hard to style \/ layout pages compared to jsp templates etc. But I [&hellip;]","og_url":"https:\/\/trifork.nl\/blog\/google-webtoolkit-remoting\/","og_site_name":"Trifork Blog","article_published_time":"2006-06-04T13:07:13+00:00","author":"Jelmer Kuperus","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Jelmer Kuperus","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/trifork.nl\/blog\/google-webtoolkit-remoting\/","url":"https:\/\/trifork.nl\/blog\/google-webtoolkit-remoting\/","name":"Google WebToolkit remoting - Trifork Blog","isPartOf":{"@id":"https:\/\/trifork.nl\/blog\/#website"},"datePublished":"2006-06-04T13:07:13+00:00","author":{"@id":"https:\/\/trifork.nl\/blog\/#\/schema\/person\/c0ee9f25744015bf661fee1b797341f2"},"breadcrumb":{"@id":"https:\/\/trifork.nl\/blog\/google-webtoolkit-remoting\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/trifork.nl\/blog\/google-webtoolkit-remoting\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/trifork.nl\/blog\/google-webtoolkit-remoting\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/trifork.nl\/blog\/"},{"@type":"ListItem","position":2,"name":"Google WebToolkit remoting"}]},{"@type":"WebSite","@id":"https:\/\/trifork.nl\/blog\/#website","url":"https:\/\/trifork.nl\/blog\/","name":"Trifork Blog","description":"Keep updated on the technical solutions Trifork is working on!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/trifork.nl\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/trifork.nl\/blog\/#\/schema\/person\/c0ee9f25744015bf661fee1b797341f2","name":"Jelmer Kuperus","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/trifork.nl\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/fff87cf8073c776ffcbe26326f713998?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/fff87cf8073c776ffcbe26326f713998?s=96&d=mm&r=g","caption":"Jelmer Kuperus"},"sameAs":["http:\/\/www.dutchworks.nl"],"url":"https:\/\/trifork.nl\/blog\/author\/jelmer\/"}]}},"_links":{"self":[{"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/posts\/2917","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/users\/58"}],"replies":[{"embeddable":true,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/comments?post=2917"}],"version-history":[{"count":0,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/posts\/2917\/revisions"}],"wp:attachment":[{"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/media?parent=2917"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/categories?post=2917"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/tags?post=2917"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}