LAB 5557 Develop a JavaFX Application, with RESTful Web Service and JSON

David Delabassée Sébastien Stormacq
Sun Microsystems, Northern Europe

com/javaone 2 .   Read the lab guide. especially the background Don't just copy and paste the solutions JavaONE 2009 | sun...Instructor-Led Hands-on Labs > > Instructors will provide background for exercises Exercises are self-paced   Hard-copy and online lab guides are available Use suggested durations as a guide > > Raise your hand at any time for assistance To get the most out of the lab.

Housekeeping > Before you leave. please fill out a survey and hand it to someone  We really want to know what you think! > > > Please log out of your machine when done Please look around to make sure you have all of your belongings The hard copies of the lab guides are yours to keep JavaONE 2009 | sun.com/javaone 3 .

Architecture Overview RIA Leveraging existing backend services REST Web Service http / json GlassFish v3 JavaONE 2009 | sun.com/javaone 4 .

object oriented language & API for Graphical Applications    Cool Language w/ data binding and triggers Rich Graphics API Multimedia ready JavaFX SDK NetBeans Samples Adobe Illustrator & Photoshop plugins > Tools for developers and designers     > Built on top of Java™ platform JavaONE 2009 | sun. declarative.com/javaone 5 .JavaFX in a nutshell > Scripting.

com/javaone 6 . cacheable. stateless.REST Architecture > REST Architecture Principles      Representational State Transfer Everything is a resource Resources are addressable Resources have an interface (operations and data types) Protocol is client-server. layered JavaONE 2009 | sun.

GET. . …) Web Service returns a MIME Type (XML. YAML... DELETE.RESTful web services > REST Applied to web services    Web Service is accessible through an URI Operations are HTTP primitives (PUT.com/javaone 7 .) > More resource efficient than SOAP JavaONE 2009 | sun. JSON.

aka aka JAX-RS  Will be part of upcoming Java EE 6 specification A Java class A set of methods The resources (the URI) The Operations The Data Types (as MIME types) RESTful web service is   > Use Java annotations to represent    > Jersey is JAX-RS Reference Implementation JavaONE 2009 | sun.RESTful Web Services > > JSR 311.com/javaone 8 .

JSON. "city": "New York".com/javaone 9 } . "address": { "streetAddress": "21 2nd Street". JavaScript Object Notation > > > A data format to exchange data structures Language independent Mainly used for object serialization and AJAX { "firstName": "John". "postalCode": 10021 }. "646 555-4567" ] JavaONE 2009 | sun. "lastName": "Smith". "phoneNumbers": [ "212 555-1234". "state": "NY".

1 JavaONE 2009 | sun.com/javaone 10 .Exercises > > > > Exercise 1: Create a JavaFX Application ● Expected duration: 20 minutes Expected duration: 30 minutes Expected duration: 30 minutes Expected duration: 20 minutes Exercise 2: Create a RESTful web service ● Exercise 3: Asynchronous calls in JavaFX ● Exercise 4: Polling the web service ● > Lab built on JavaFX 1.

log in with   username: lab5557 password: hol009 > > Online lab guide will open in a browser window All necessary software and lab files are already installed on your lab machine  Start from exercise 1 JavaONE 2009 | sun.com/javaone 11 .Getting Started > If you have not logged in.

sun.com/sebsto > Add an existing PieChart component   > PieChartFX is open source   JavaONE 2009 | sun.Exercise 1 > Create your first JavaFX application   Create the project Build.com/javaone 12 . Run and Test Modify the application Build Run and Test Online tutorial to build it from scratch http://blogs.

Build. Run and Test Will return application/json data type Build. Run and Test Will return text/plain data type Build.com/javaone 13 .Exercise 2 > > Create a Web Application  Create. Run and Test Add a RESTful web service   > Add a method that will return JSON data   JavaONE 2009 | sun.

Exercise 3 > > > Return to the JavaFX Application Add an asynchronous call to the RESTful web service Use Java based JSON parser to parse the result var request : RemoteTextDocument = RemoteTextDocument { url: "http://host/MyWebService/resources/values".document on replace { if (request. } var value: String = bind request.done) { //do something with value } } JavaONE 2009 | sun.com/javaone 14 .

schedule(task. 5000). 0.util. JavaONE 2009 | sun. timer.Exercise 4 > Add polling capabilities to JavaFX   Reuse existing java.Timer class Poll every 5000 ms class PieChartTask extends TimerTask { override function run() { //wrap existing connection and parsing code } }. def task : PieChartTask = new PieChartTask(). def timer : Timer = new Timer("TimerThread").com/javaone 15 .

please consider taking the lab exercises with you   Discs containing all of the labs offered this year are available for you to take home The lab guide will tell you where to get help with this lab after JavaOne > Thank you for attending this hands-on lab! JavaONE 2009 | sun.Congratulations! > > You should now have completed this lab If you would like more time to continue working.com/javaone 16 .

com 17 .com Sébastien Stormacq Sun Microsystems.delabassee@sun.stormacq@sun.David Delabassée david. Northen Europe JavaONE 2009 | sun.com/javaone sebastien.