Slashdot Mirror


DWR Makes Interportlet Messaging With AJAX Easy

An anonymous reader writes "You can use the sample code in this article as a starting point for developing your own applications; the code also shows how DWR extends the Java programming model to Web browsers. With DWR, it's almost as if JavaBeans were available in the browser. DWR simplifies your work by hiding almost all the details of Ajax and allows you to concentrate on the task at hand instead of the nuts and bolts of Ajax development."

39 comments

  1. Thank God... by Anonymous Coward · · Score: 0

    I was worried I might not be able to easily let my interportlets message each other. They're so lonely!

  2. Expanding? by rowama · · Score: 1

    Ajax uses a combination of XML, HTML, DHTML, JavaScript, and DOM.

    Is it me, or does the scope of Ajax seem to be expanding?

    1. Re:Expanding? by Aladrin · · Score: 2, Informative

      Nope, it's always been all those. Remove any 1 of them and AJAX doesn't exist.

      --
      "If you make people think they're thinking, they'll love you; But if you really make them think, they'll hate you." - DM
    2. Re:Expanding? by ben+there... · · Score: 2, Informative

      DHTML combines HTML, JS, DOM, and CSS.

      XML is in many cases the best method of sending data to the AJAX script.

      Both have been part of AJAX all along.

    3. Re:Expanding? by mwvdlee · · Score: 3, Informative

      It's you.

      Basically, AJAX is a website that uses HTTPRequest.
      The XML, HTML, DHTML, JavaScript and DOM are just logical extensions of that premise. Similarly you could say AJAX also uses TCP/IP and HTTP. Though, likewise, it says nothing.

      --
      Slashdot social media options: AIM, ICQ, Yahoo, Jabber and Mobile Text. Why no MySpace?
    4. Re:Expanding? by rowama · · Score: 1

      Nice thing about /. is that one can learn something new. Before, I had the mistaken notion that Ajax was simply concerned with using XMLHttpRequest to avoid large HTTP transactions and page reloads. Now, I realize this has to involve DOM to make it useful. However, it does not require XML, or XHTML, to work. If you use JSON you can eliminate XML and still have Ajax (eventhough XML is implied in the name).

      If you will kindly confirm this understanding of Ajax, I can safely store the new rule away in the dusty recesses of my mind.

    5. Re:Expanding? by complete+loony · · Score: 1

      I had a little project that did just that. Using a java applet to multicast packets to all peers on an intranet site. Javascript, Java, DHTML, IE 4, and TCP/IP (plain html server side in this case). WAAAAAY before AJAX or even XMLHTTPRequest (I believe) was invented.

      --
      09F91102 no, 455FE104 nope, F190A1E8 uh-uh, 7A5F8A09 that's not it, C87294CE no. Ah! 452F6E403CDF10714E41DFAA257D313F.
    6. Re:Expanding? by Aladrin · · Score: 1

      Yes, technically you could send an xmlhttprequest without any xml. But since a large part of 'ajax' is the dynamic pages resulting from the request, you can't really do 'AJAX' without the XHTML, at the very least. (And for what little it's worth, XHTML is really just specific XML.)

      --
      "If you make people think they're thinking, they'll love you; But if you really make them think, they'll hate you." - DM
    7. Re:Expanding? by aztracker1 · · Score: 1

      Well, it's not XML, but you can do AJAX (at least the style) with JSON encoding rather than XML responses... JSON evaluates into JavaScript much faster than XML does, it is also, in general far smaller than XML is in regards to size.

      The biggest issue with JSON over XML, is de-encoding in server-side platforms. I'm aware of a few server-side platforms that work in JavaScript but none, afaik are in wide use (outside of classic asp). Anthem uses JSON, not sure about Rails, and not sure what else uses it, but it is a great option when somewhat bandwidth constrained.

      --
      Michael J. Ryan - tracker1.info
    8. Re:Expanding? by LDoggg_ · · Score: 1

      you can't really do 'AJAX' without the XHTML

      Why not?
      You don't have to apply a stylesheet and convert to xhtml on the client. You can simply read the DOM and create HTML from javascript. Or you could just send preformatted html. Or you could use JSON as has been mentioned.

      --

      "If they have both, tell them we use Linux. And if they have that, tell them the computers are down." -Dave Chapelle
    9. Re:Expanding? by Anonymous Coward · · Score: 0

      It all falls down when the user or their settings disables javascript. None of it works. Totally unreliable.

  3. What the hell? by david.given · · Score: 1

    "Interportlet"?

    1. Re:What the hell? by no_barcode · · Score: 1

      A portlet is like a Java applet, except it's built specifically as a little program that runs inside a web portal. There are some very rigid rules it must follow to be considered a portlet. It's like a plug-in.

      I've found that if you have a problem with your portlet, you can plug it up with your Ajax and prevent any sort of embarrassing leaks. Ajax has amazing absorption, and it's very comfortable because it's designed with portlets in mind. So it feels like you're not even wearing an Ajax. It's great!

    2. Re:What the hell? by Anonymous Coward · · Score: 0

      I'm not sure what it is, but I think it's got something to do with Chloe from 24 and self-defending Cisco firewalls.

    3. Re:What the hell? by jo42 · · Score: 1

      New buzzword to BS VCs. Spiffy.

    4. Re:What the hell? by Manitcor · · Score: 1

      hardly a buzz word and hardly new: http://en.wikipedia.org/wiki/Portlet

      other names that have been used in the past are:
      gadget
      web part
      pagelet

      An industry group of the major enterprise portal companies got together and worked on standarizing some things like what to name those little "sub pages". This is also the same group that brought you the JSR-168 specification and to some extent WSRP.

      --
      "Don't mess with him, he taunts the happy fun ball."
    5. Re:What the hell? by Reverend528 · · Score: 2, Insightful

      Clearly you've never read the JSR-168 spec or you'd know that portlets are little web applications that adhere to standards so crippling that the easiest way to communicate between two portlets on the same server is to utilize the clients' web browser in a convoluted AJAX hack.

    6. Re:What the hell? by aztracker1 · · Score: 1

      Honestly, this is probably going to be marked as a troll. But it sounds like a pretty typical java based solution to me... Don't get me wrong, I like java, but every web/http/html implimentation (not browser applets) I've seen or worked with makes me sick to my stomach.

      --
      Michael J. Ryan - tracker1.info
  4. Nuts and bolts? by The+MAZZTer · · Score: 3, Insightful

    "'...allows you to concentrate on the task at hand instead of the nuts and bolts of Ajax development.'"

    Last time I checked the "nuts and bolts" of AJAX was only a few dozen lines of code... all it is is sending a server request in the background.

    1. Re:Nuts and bolts? by dnebin · · Score: 1

      The request send/retrieve may only be a few dozen lines, but the dom handling and data marshalling on both sides typically exceeds that line count.

  5. Re:Inter-portlet by Anonymous Coward · · Score: 0

    It's missing the hyphen.

    Inter-portlet communication
    As in, communication between portlets.

    Portlets are a specific type of J2EE application.

  6. DWR.. by RalphSleigh · · Score: 2, Funny

    I didnt RTFM or TFS but WTF does DWR stand for?

    --
    Come as you are, do what you must, be who you will.
    1. Re:DWR.. by cyranoVR · · Score: 1

      DWR - Direct Web Remoting

      It can be pretty much summed up as "RMI-like functionality implemented with JavaScript." Having used DWR, I'm not really sure if it uses XMLHttpRequest or something else, because the library abstracts that from the application developer. The server-side can code POJOs and the client-side can code against JavaScript functions. The DWR servlet and configuration file are the "glue" that gets the client-side to the server-side objects.

      The limitation I've bumped up against is that the DWR servlet expects all remoting requests to come in via a serlvet mapping of /your_context/dwr/*, which makes is difficult to work with existing web applications that application parameters embedded in the URL path. This can be overcome by implementing a pluggable interface, but it's enough to make me look at using ad-hoc JSON generated from jsp pages instead...

  7. Interportlet Messaging Is A Euphamism For... by Doomedsnowball · · Score: 1

    Google Gadget viruses.

    --
    7h3$3 4r3n'7 7h3 Ðr01Ð$ ¥0 4r3 £00|{1n9 f0r. M0v3 4£0n9. --OB1
  8. Complexisity is more enterprisey by Reverend528 · · Score: 0, Flamebait
    True, java solutions seem confusing and misengineered when you look at them up close, but if you take a step back you'll realize that the usability and maintainability isn't lost, but has been traded for a vast quantity of enterprise. If you don't believe me, just perform these simple calculations to see how much enterprise your software is worth:

    Number of Megabytes required to run software * Maximum depth of class hierarchy * Number of lines of XML configuration = Enterprise!

  9. Design Within Reach? by Onan · · Score: 1


    Am I the only one who was wondering what exactly Design Within Reach had done to improve AJAX? I mean, sure, I really like some of their lamps, but I think that AJAX is beyond even their power to salvage.

    1. Re:Design Within Reach? by dnebin · · Score: 1

      DWR = Direct Web Remoting in this situation. DWR is a tool for marshalling java beans from the servlet side into javascript objects on the client side whilst taking care of the AJAX request/response cycle, etc. Using DWR to it's fullest you don't need to write a line of servlet/javascript code for the communication.

  10. Please, drop JSP and XML config files... by master_p · · Score: 1

    Can we please drop JSP? writing java code within HTML is very very bad.

    In the same line of thought, can we drop the millions of XML config files needed for this sort of stuff? they are not needed.

    I am using Echo2 for intranet applications and it works fine. No HTML, no XML. Coding the GUI is exactly like Swing. But the problem is that every action in the client triggers a response from the server...if I could program Java classes and the bytecode was translated to javascript on the fly, then I could write normal Java apps which would be executed as javascript on the client, thus minimizing the client-server communication.

    Javascript and the web browser are nothing more than a bad implementation of the the NeWS Window System anyway...with NeWS, one could write a sort of postscript-like program to be executed on the display server (i.e. client), thus limiting communication between client and server to the absolutely minimal stuff.

    1. Re:Please, drop JSP and XML config files... by Anonymous Coward · · Score: 0
      writing java code within HTML is very very bad.
      Actually, its saved me a lot of time in the past.
    2. Re:Please, drop JSP and XML config files... by Anonymous Coward · · Score: 0

      >>Can we please drop JSP? writing java code within HTML is very very bad.

      Guess that means no more PHP or ASP either?

    3. Re:Please, drop JSP and XML config files... by Anonymous Coward · · Score: 0

      GWT

    4. Re:Please, drop JSP and XML config files... by aevans · · Score: 1

      There's a reason why every computer has a browser but none of them have java GUIs. And it isn't Microsoft. If people wanted Swing apps they'd have them, whether Microsoft provided them or not. People aren't that loyal to the OS. But people wanted a browser, and Microsoft was force to develop one to compete. Microsoft dropped their JRE because no one wanted it.

    5. Re:Please, drop JSP and XML config files... by Anonymous Coward · · Score: 0

      mixing (X)HTML and and any kind script code in the *same file* with processing directives
      like <?, <% etc breaks encapsulation and introspection into your codebase, costing you
      time and scaleability in the long run. half the reason "web 1.0" "failed"...
      keep the presentation layer and business logic seperate if you don't want to make an
      unmaintainable mess. In fact how doing it in such a crippled way can be said to "save time"
      is beyond me! it's more that a serious lack of application server tools forced such an
      incoherent methodology on us ten years ago, and sad to say but that antipattern is now
      firmly entrenched in the industry by people who "know best" and don't want to know better...

      okay just ranting there...

    6. Re:Please, drop JSP and XML config files... by Anonymous Coward · · Score: 0

      Can we please drop JSP? writing java code within HTML is very very bad.

      Well yeah, that's why 8 years ago jsp taglibs came out. Get with the program.

  11. I want benchmarks. by SanityInAnarchy · · Score: 1

    Since the browser is doing the XML evaluating, and since a smart browser is going to be doing something like XML evaluating all day long (especially if you actually send XHTML as application/xhtml+xml), the browser probably has a very fast C or assembly XML parser. It probably isn't being evaluated in JavaScript.

    So I have two questions: Is the browser's XML parser faster than the browser's JavaScript parser? (Probably, but I want benchmarks.)

    And, on the server side, you have the same issue -- is it faster to generate XML (with one of many XML parsers/generators) or to generate JSON (which is simpler, but you probably end up using something written in the language -- IE, a pure perl JSON generator, or pure PHP, whereas with XML you're calling a C generator from the Perl or PHP)?

    The fact that JSON is physically smaller probably matters some, though not much if you're gzipping it anyway.

    It's also entirely conceivable that some custom, simpler language than either JSON or XML could be developed, that parses faster in JavaScript than either XML or JSON do in the browser. I doubt it, but as long as you're benchmarking stuff...

    --
    Don't thank God, thank a doctor!
  12. The DOM is what will kill you... by SanityInAnarchy · · Score: 1

    It's not the AJAX, it's the DHTML. And now that there's more interest in the DHTML and use of the DOM in JavaScript (all due to AJAX), people are actually trying to do cross-browser implementations, because Firefox is also getting much more popular -- you can no longer create a DHTML (or AJAX) site that works only in IE.

    I mean, you're right, it's easier than it looks to someone who doesn't know how to do it, but it's harder than it looks to someone who does.

    --
    Don't thank God, thank a doctor!
  13. This sounds like by Joff_NZ · · Score: 1

    This sounds exactly like the Google Web Toolkit ....

    --
    The revolution will not be televised. It won't be on a friggin blog either
    1. Re:This sounds like by kap1 · · Score: 1

      Actually, DWR exposes POJO's on the server via Javascript peers in the client.

      GWT, on the other hand, is really two things in one: first, it compiles Java code to Javascript, much like javac converts Java to bytecode; big portions of java.lang and java.util are available to the developer. Second, it allows you to execute and debug your code in a JVM. The idea is that the code in the JVM will behave exactly like the compiled Javascript code in the browser.

      I think the point of GWT is that good Java programmers are easy to find whereas good Javascript/CSS/XHTML programmers are hard to find. This way they can write Java and produce Javascript. For more on GWT, see here.

  14. Problems by brunes69 · · Score: 2, Insightful

    This DMR *seems* cool at first, but the fact that I have to inline the Javascript code insid ethe JSP with this stupid cusotm tag kills it for me. JSP's are supposed to be the presentation layer *only* - if you have JS code it should be in external .js files as much as humanly possible. THis also helps download times a lot since the .js files can be cached.

    Personally I think that JSON-RPC is far superior to this "DMR" stuff. It's also been around much longer, so it's tried and tested. It also has non-Java backend implementations.