Activate your free membership today | Log-in

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:

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

Related Content:

  • Ajax apps with DWR
    A newly released podcast covers Ajax and Direct Web Remoting (DWR) including inside tips on using the Java open source library. It also covers common...
  • Using DWR with TIBCO General Interface
    This simple request/response cycle example demonstrates some of the basic utilities Direct Web Remoting (DWR) provides for making interactions between...
  • Ajax for Java
    DWR 1.0, designed to allow for easier Ajax development inside Java, has been released with remote JavaScript calls into Java, automatic JavaScript...
  • Why portlet programmers avoid PortletPreferences for performance
    Some parts of the portlet API are amazing, but there are some pitfalls as well, especially when it comes to developing portlet applications that use...
  • NetBeans portlet plugin released
    The initial release of the "Portal Pack NetBeans Portlet Plugin," allows development of portlets and their deployment into the open-source Portlet...

Posted by Dion Almaer at 10:21 am
1 Comment

+++--
3.9 rating from 62 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.