Friday, July 14th, 2006

Ajax Portlet Communication with DWR

Category: Articles, Portal

<p>Sami Salkosuo has added fuel to the fire of the claims that “Ajax is perfect for portals and portlets, and we can finally do them right” with his piece DWR makes interportlet messaging with Ajax easy:

Many developers are looking to use Ajax technologies to improve the user experience of Web-based applications, but Ajax programming can be a tricky task. The open source Direct Web Remoting (DWR) library can make Ajax development easier for Javaâ„¢ developers by automatically transforming Java classes into JavaScript classes. In this article, you’ll learn how how to use DWR and JSR-168-compliant portlets to build an Ajax application quickly and easily.

The article has a lot of code to show by example, how this all works, most of it Java, with a touch of JSP:

  1. < %@ page contentType="text/html"
  2. import="java.util.*,javax.portlet.*,interportletmessagingusingajax.*" %>
  3. < %@taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
  4. <portlet :defineObjects/>
  5.  
  6. <script type="text/javascript"
  7.     src='<%= renderResponse.encodeURL(renderRequest.getContextPath() +
  8.     "/dwr/interface/MessagingBean.js") %>'>
  9. </script>
  10.  
  11. <script type="text/javascript"
  12.     src='<%= renderResponse.encodeURL(renderRequest.getContextPath() +
  13.     "/dwr/engine.js") %>'>
  14. </script>
  15.  
  16. <script type="text/javascript">
  17.  
  18. function <portlet :namespace />sendOrderNr(orderNr)
  19. {
  20. document.getElementById("orderDetailsOrderNumber").innerHTML=orderNr;
  21. document.getElementById("customerDetailsOrderNumber").innerHTML=orderNr;
  22. MessagingBean.getOrderDetails(orderNr,<portlet :namespace />showOrderDetails);
  23. MessagingBean.getCustomerDetails(orderNr,<portlet :namespace />showCustomerDetails);
  24.  
  25. return false;
  26. }
  27.  
  28. function <portlet :namespace />showOrderDetails(orderDetails)
  29. {
  30. document.getElementById("orderDetails").innerHTML=orderDetails;
  31. return false;
  32. }
  33.  
  34. function <portlet :namespace />showCustomerDetails(customerDetails)
  35. {
  36. document.getElementById("customerDetails").innerHTML=customerDetails;
  37. return false;
  38. }
  39. </script>

Related Content:

Posted by Dion Almaer at 10:21 am
1 Comment

+++--
3.9 rating from 67 votes

1 Comment »

Comments feed TrackBack URI

I NEED HELP. PLEASE GO TO http://www.tygodnik-zamojski.pl and in “election little miss and mister” (red icon at left side screen) and election candidate on position C74. THANK YOU VERY MUCH FOR VOICE. (It’s one click on link “GŁOSUJ +” under candidate)

Comment by tata — July 27, 2006

Leave a comment

You must be logged in to post a comment.