What's new in DWR version 3

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    2 Favorites

    What's new in DWR version 3 - Presentation Transcript

    1. What’s new in DWR v3 Joe Walker DWR Lead Developer SitePen UK
    2. Recap Since we last talked ... Named Parameters Binary Files JavaScript Extending Java Better Reverse Ajax Data Sync: Dojo Data Store JSON / JSONP / JSON-RPC Varargs and Overloaded Methods What’s Next © SitePen, Inc. 2008. All Rights Reserved
    3. Recap © SitePen, Inc. 2008. All Rights Reserved
    4. © SitePen, Inc. 2008. All Rights Reserved
    5. Marshalling Types Primitive types, and their Object counterparts int, boolean, long, float, double, etc Obvious classes String, Date, BigDecimal, BigInteger, Enum, etc Arrays and Collections Map, List, Set, Iterator, ... JavaBeans and Objects XML objects DOM, XOM, JDom, Dom4J © SitePen, Inc. 2008. All Rights Reserved
    6. © SitePen, Inc. 2008. All Rights Reserved
    7. Since we last talked ... TIBCO General Interface SitePen http://svn.directwebremoting.org © SitePen, Inc. 2008. All Rights Reserved
    8. Named Parameters © SitePen, Inc. 2008. All Rights Reserved
    9. Named Parameters DWR will create client-side classes to look like server-side classes to make passing parameters easy © SitePen, Inc. 2008. All Rights Reserved
    10. Named Parameters Java: public interface Person { ... } public class Employee implements Person { ... } public class Manager extends Employee { ... } public HumanResources { public void addPerson(Person p) { ... } } JavaScript: Manager m = new Manager(); HumanResources.addPerson(m); © SitePen, Inc. 2008. All Rights Reserved
    11. Named Parameters Why? • Inheritance is useful in places • It saves creating addEmployee() and addManager() methods © SitePen, Inc. 2008. All Rights Reserved
    12. Lightweight Named Parameters © SitePen, Inc. 2008. All Rights Reserved
    13. Lightweight Named Parameters DWR also allows a lighter-weight method of declaring types © SitePen, Inc. 2008. All Rights Reserved
    14. Lightweight Named Parameters Java: public interface Person { ... } public class Employee implements Person { ... } public class Manager extends Employee { ... } public HumanResources { public void addPerson(Person p) { ... } } JavaScript: var m = { $dwrClassName:'Manager', firstname:'Joe', ...}; HumanResources.addPerson(m); © SitePen, Inc. 2008. All Rights Reserved
    15. Lightweight Named Parameters Why? • Everything as for Named Parameters • But sometimes you get an object from somewhere else © SitePen, Inc. 2008. All Rights Reserved
    16. Binary Files: File Upload © SitePen, Inc. 2008. All Rights Reserved
    17. Binary Files: File Upload DWR has always had a long list of things that it will marshall including Dates, DOM trees, etc In addition, DWR will now marshall binary files just as if they were the text resources it handles now © SitePen, Inc. 2008. All Rights Reserved
    18. Binary Files: File Upload Java: public Remoted { public void receiveBinaryFile(byte[] uploaded) { ... } } HTML: <input id='fileId' type='file'/> JavaScript: var binary = dwr.util.getValue('fileId'); Remoted.receiveBinaryFile(binary); © SitePen, Inc. 2008. All Rights Reserved
    19. Binary Files: File Upload Will marshall to: • byte[] • java.awt.BufferedImage • java.io.InputStream • org.directwebremoting.io.FileTransfer (gives access to filename and mime-type in addition to the contents) © SitePen, Inc. 2008. All Rights Reserved
    20. Binary Files: File Upload Why? • This is a lot easier than using commons-fileupload or similar • We can provide integration with progress bar widgets © SitePen, Inc. 2008. All Rights Reserved
    21. Binary Files: Download © SitePen, Inc. 2008. All Rights Reserved
    22. Binary Files: Download Binary file handling is 2 way. It’s good for: • Images • PDF files • Word, Excel documents • etc. © SitePen, Inc. 2008. All Rights Reserved
    23. Binary Files: Download Java: public Remoted { public void getPDF(String contents) { ByteArrayOutputStream buf = new ByteArrayOutputStream(); Document doc = new Document(); PdfWriter.getInstance(doc, buf); doc.open(); doc.add(new Paragraph(contents)); doc.close(); return new FileTransfer(\"ex.pdf\", \"application/pdf\", buf.toByteArray()); } JavaScript: Remoted.getPDF('Joe', function(data) { dwr.engine.openInDownload(data); }); © SitePen, Inc. 2008. All Rights Reserved
    24. Binary Files: Download Why? • This is a lot easier than creating a special PDF/ image/etc serving servlet © SitePen, Inc. 2008. All Rights Reserved
    25. Javascript extending Java © SitePen, Inc. 2008. All Rights Reserved
    26. Javascript extending Java DWR will allow you to implement Java interfaces using JavaScript © SitePen, Inc. 2008. All Rights Reserved
    27. Javascript extending Java Java: public interface BazListener { void somethingChanged(String msg); } public class Remote { public void addBazListener(BazListener bl) { ... } public void calledLater() { for (BazListener bl : listeners) bl.somethingChanged(\"JS objects can implement Java interfaces\"); } ... } JavaScript: function BazListener() {this.$dwrByRef;} BazListener.prototype.somethingChanged = function(msg){alert(msg);}; var bl = new BazListener(); Remote.addBazListener(bl); © SitePen, Inc. 2008. All Rights Reserved
    28. Javascript extending Java Why? • Intuitive way to interact • Easy Pub-sub • Allows interaction with existing APIs © SitePen, Inc. 2008. All Rights Reserved
    29. Scalable Reverse Ajax © SitePen, Inc. 2008. All Rights Reserved
    30. Scalable Reverse Ajax Previously there were some scalability limitations with the 2.0 reverse ajax API. 3.0 deprecates the problem areas. © SitePen, Inc. 2008. All Rights Reserved
    31. Scalable Reverse Ajax Reverse Ajax proxies no longer take a list of ScriptSessions in the constructor, they just write to the current ‘destination’ The Browser API allows you to change the current ‘destination’ © SitePen, Inc. 2008. All Rights Reserved
    32. Scalable Reverse Ajax // The default destination is the browser // that caused the current action to happen. Window.alert(\"Hello\"); // Non DWR thread have no default destination Thread t = new Thread(new Runnable()) { public void run() { // Error Window.alert(\"Hello\"); } }); © SitePen, Inc. 2008. All Rights Reserved
    33. Scalable Reverse Ajax // Set the destination to be all browsers that // are looking at the current page Browser.withCurrentPage(new Runnable()) { public void run() { Window.alert(\"Hello\"); } }); // Set the destination to be all browsers that // are looking at the current page Browser.withCurrentPage(\"index.html\", new Runnable()) { public void run() { Window.alert(\"Hello\"); } }); © SitePen, Inc. 2008. All Rights Reserved
    34. Scalable Reverse Ajax // Broadcast to everyone Browser.withAllSessions(...); // Broadcast to subsets Browser.with*Filtered(scriptSesssionFilter, ...); // To a known individual Browser.withSession(sessionId, ...); © SitePen, Inc. 2008. All Rights Reserved
    35. Scalable Reverse Ajax Why? • It’s generally easier to use • It decouples generation from routing • It scales © SitePen, Inc. 2008. All Rights Reserved
    36. Reverse Ajax APIs © SitePen, Inc. 2008. All Rights Reserved
    37. Reverse Ajax APIs Reverse Ajax != Comet Reverse Ajax == Comet + Polling + Piggyback © SitePen, Inc. 2008. All Rights Reserved
    38. Reverse Ajax APIs: JS Level // Low level: Use server-side W3C DOM methods Element ele = doc.createElement(\"p\"); ScriptSessions.addFunctionCall( \"document.body.appendChild\", ele); © SitePen, Inc. 2008. All Rights Reserved
    39. Reverse Ajax APIs: JS Level // Low level: Any arbitrary JavaScript String s = \"if (document.all) window.alert('IE');\"; ScriptSessions.addScript(s); © SitePen, Inc. 2008. All Rights Reserved
    40. Reverse Ajax APIs: DOM Level // Some methods from Window and Document import javax.servlet.http.Cookie; import org.directwebremoting.ui.browser.Document; Cookie c = new Cookie(\"name\", \"value\"); Document.setCookie(c); © SitePen, Inc. 2008. All Rights Reserved
    41. Reverse Ajax APIs: dwr.util // dwr.util in Java import org.directwebremoting.ui.dwr.Util; String[] opts = new String[] {\"one\",\"two\",...}; Util.addOptions(\"li\", opts); © SitePen, Inc. 2008. All Rights Reserved
    42. Reverse Ajax APIs: Scriptaculous // Scriptaculous Effects in Java import org.directwebremoting.ui.scriptaculous.Effect; Effect.fade(\"someId\"); © SitePen, Inc. 2008. All Rights Reserved
    43. Reverse Ajax APIs: TIBCO GI // TIBCO General Interface in Java import jsx3.GI; import jsx3.app.*; import jsx3.gui.*; Server server = GI.getServer(\"servername\"); TextBox phoneNum = server.getJSXByName(\"phoneNum\", TextBox.class); phoneNum.setValue(\"servername\"); © SitePen, Inc. 2008. All Rights Reserved
    44. Reverse Ajax APIs: Dojo // Dojo in Java import org.dojotoolkit.dijit.Dijit; import org.dojotoolkit.dijit.Editor; Editor e = Dijit.byId(\"price\", Editor.class); e.setValue(42); © SitePen, Inc. 2008. All Rights Reserved
    45. Scalable Reverse Ajax Why? • A full range of APIs for dynamically updating client data • DWR doesn’t do widgets, but it does talk to the people that do Drapgen can be used to create and maintain large APIs © SitePen, Inc. 2008. All Rights Reserved
    46. Dojo Data Store © SitePen, Inc. 2008. All Rights Reserved
    47. Dojo Data Store DWR now implements all 4 interfaces to allow Dojo to sync data with Java code on the server © SitePen, Inc. 2008. All Rights Reserved
    48. Dojo Data Store Java: // Load the data somehow Map<String, Person> ppl = ...; // Create an implementation of StoreProvider to hold the data MapStoreProvider provider = new MapStoreProvider(ppl, Person.class); // Tell DWR to expose the data to the internet Directory.register(\"testServerData\", provider); © SitePen, Inc. 2008. All Rights Reserved
    49. Dojo Data Store HTML: <table id=\"grid\" dojoType=\"dojox.grid.DataGrid\" ><tr> <th field=\"name\" width=\"120px\" editable=\"true\">Name</th> ... </tr></table> JavaScript: dojo.registerModulePath(\"dwr\", \"path/from/dojo/to/dwr\"); dojo.require(\"dwr.data.Store\"); dwrStore = new dwr.data.Store(\"testServerData\", { subscribe:true }); dijit.byId(\"grid\").setStore(dwrStore); © SitePen, Inc. 2008. All Rights Reserved
    50. Dojo Data Store Java: // The StoreProvider from earlier MapStoreProvider provider = ... // Get a representation of the internal data Map<String, Person> data = provider.asMap(); // Mutate it data.addPerson(new Person(...)); // The browsers viewing the data automagically update © SitePen, Inc. 2008. All Rights Reserved
    51. Dojo Data Store Why? • Data-Sync APIs are hard to get right, but are really simple to use • There is lots of potential for network level optimization © SitePen, Inc. 2008. All Rights Reserved
    52. JSON / JSONP / JSON-RPC © SitePen, Inc. 2008. All Rights Reserved
    53. Dojo Data Store DWR now supports: • plain JSON • JSONP • JSON-RPC © SitePen, Inc. 2008. All Rights Reserved
    54. JSONP Java: public class Demo { public sayHello(String name) { return \"Hello, \" + name; } } Shell: $ wget http://example.com/app/dwr/jsonp/Demo/sayHello? ↩ callback=callback&param0=\"Joe\" -> callback(\"Hello, Joe\"); © SitePen, Inc. 2008. All Rights Reserved
    55. JSONP Dojo: dojo.io.script.get({ url:'http://example.com/app/dwr/jsonp/Demo/sayHello', content:{param:'Joe'} }).addCallback(function() { ... }); JQuery: $.ajax({ dataType:'jsonp', data:'param=Joe', url:'http://example.com/app/dwr/jsonp/Demo/sayHello', success:function () { ... }, }); © SitePen, Inc. 2008. All Rights Reserved
    56. JSON / JSONP / JSON-RPC Why? • To allow DWR to remote functions to things other than a DWR client • ‘DWRP’ is designed to be something we can change without a long deprecation process © SitePen, Inc. 2008. All Rights Reserved
    57. Varargs © SitePen, Inc. 2008. All Rights Reserved
    58. Varargs You can now call methods with a vararg parameter © SitePen, Inc. 2008. All Rights Reserved
    59. Varargs Java: public Remoted { public void method(String... arg) { ... } } JavaScript: Remoted.method(\"One\", \"Two\", \"Three\"); © SitePen, Inc. 2008. All Rights Reserved
    60. Varargs Why? • It saves the hassle of wrapping options in an array or collection before a method is called Alert: • It could break some corner cases when mixing servlet parameters with normal parameters © SitePen, Inc. 2008. All Rights Reserved
    61. Overloaded Methods © SitePen, Inc. 2008. All Rights Reserved
    62. Overloaded Methods Previously DWR prevented you from reliably calling overloaded methods © SitePen, Inc. 2008. All Rights Reserved
    63. Overloaded Methods Java: public Remoted { public void method(int num) { log.debug(\"int method called with \" + num); } public void method(String str) { log.debug(\"String method called with \" + str); } } JavaScript: Remoted.method(\"String Param\"); Remoted.method(42); © SitePen, Inc. 2008. All Rights Reserved
    64. Overloaded Methods Why? • It saves you from creating multiple proxy methods to existing APIs © SitePen, Inc. 2008. All Rights Reserved
    65. What’s Next © SitePen, Inc. 2008. All Rights Reserved
    66. Top Directions for DWR 3.1 Shorter release cycle Gears SMD Dojo: • Reverse Ajax API support • Auto-build Rest © SitePen, Inc. 2008. All Rights Reserved
    67. Any Questions? • http://directwebremoting.org • http://sitepen.com © SitePen, Inc. 2008. All Rights Reserved

    + Joe WalkerJoe Walker, 2 years ago

    custom

    7130 views, 2 favs, 10 embeds more stats

    A presentation of the new features in DWR version 3 more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 7130
      • 6994 on SlideShare
      • 136 from embeds
    • Comments 0
    • Favorites 2
    • Downloads 154
    Most viewed embeds
    • 61 views on http://joel.barciausk.as
    • 36 views on http://www.blogjava.net
    • 22 views on http://www.sitepen.com
    • 6 views on http://www.java2go.net
    • 4 views on http://itspice.net

    more

    All embeds
    • 61 views on http://joel.barciausk.as
    • 36 views on http://www.blogjava.net
    • 22 views on http://www.sitepen.com
    • 6 views on http://www.java2go.net
    • 4 views on http://itspice.net
    • 2 views on http://enricod.blogspot.com
    • 2 views on http://blog.beyondsolutions.it
    • 1 views on http://209.85.129.132
    • 1 views on http://www.hanrss.com
    • 1 views on http://cache.baidu.com

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories