YOUR FEEDBACK
Jeremy Geelan wrote: In response to inquiries and suggestions from readers this lexicon has recently...


2008 East
DIAMOND SPONSOR:
Data Direct
Frontiers in Data Access: The Coming Wave in Data Services
PLATINUM SPONSORS:
Red Hat
The Opening of Virtualization
Intel
Virtualization – Path to Predictive Enterprise
Green Hills
IT Security in a Hostile World
JBoss / freedom oss
Practical SOA Approach
GOLD SPONSORS:
Software AG
The Art & Science of SOA: How Governance Enables Adoption
PlateSpin
Effective Planning for Virtual Infrastructure Growth
Fujitsu
Automated Business Process Discovery & Virtualization Service
Ceedo
Workspace Virtualization
Click For 2007 West
Event Webcasts

2008 East
PLATINUM SPONSORS:
Appcelerator
Think Fast: Accelerate AJAX Development with Appcelerator
GOLD SPONSORS:
DreamFace Interactive
The Ultimate Framework for Creating Personalized Web 2.0 Mashups
ICEsoft
AJAX and Social Computing for the Enterprise
Kaazing
Enterprise Comet: Real–Time, Real–Time, or Real–Time Web 2.0?
Nexaweb
Now Playing: Desktop Apps in the Browser!
Sun
jMaki as an AJAX Mashup Framework
POWER PANELS:
The Business Value
of RIAs
What Lies Beyond AJAX?
KEYNOTES:
Douglas Crockford
Can We Fix the Web?
Anthony Franco
2008: The Year of the RIA
Click For 2007 Event Webcasts
SYS-CON.TV
TOP THREE LINKS YOU MUST CLICK ON


SOA - Enterprise Mashup Services
Part 1: Real-World SOA or Web 2.0 Novelties?

The JavaScript functions used to update and insert entries make use of the addMarkerForCustomers function. The createCustomer, updateCustomer, and removeCustomer functions share similar code and for the sake of brevity only the create updateCustomer Customer function is described in this article. See Listing 1 for a detailed look at the createCustomer and removeCustomer functions.

The updateCustomer function calls a utility function, DWRUtil.getValues, provided by DWR that extracts values from HTML elements that contain ids that map to name/value pairs contained in a JavaScript object. In this example the DWRUtil.getValues function is used to populate a Customers JavaScript object that is persisted using the JavaServiceFacade.mergeCustomers function. The JPA merge operation updates the corresponding record in the database. The second argument passed to the JavaServiceFacade.mergeCustomers function is an anonymous function that's called after the Customers object is merged and is used to delete the currently selected marker. The deleted marker is replaced with a new one representing the changes to the Customers entity.

The removeSelectedMarker function is responsible for removing the currently selected marker on the map. The function uses the Google Maps API to close the caption for the selected marker and remove the marker from the overlay.

// Updates the currently selected customer
function updateCustomer(){
...
   DWRUtil.getValues(customer);
   // Remotely call Java method
   // to update record
   JavaServiceFacade.mergeCustomers(
     customer,
     function(){
     // remove selected marker
     removeSelectedMarker();
     // add new marker with updates
     addMarkerForCustomer(customer);
   });
...
}

// Removes the currently selected marker
function removeSelectedMarker(){
...
   // close the caption window
   map.closeInfoWindow();
   // remove the current marker
   map.removeOverlay(currentMarker);
...
}

The updateCustomer function and similarly the createCustomer and removeCustomer functions are invoked when a user clicks a form button on a page. Attaching the createCustomer function to the onclick event fired by the button when it's clicked makes the association between the button and the updateCustomer function. Thus, a single click of an HTML form button creates a Customers JavaScript object that's converted to a JPA entity and persisted to a database.

<button id="update" onclick="updateCustomer();">
    Update
</button>

Clicking a marker on the map populates the customer form in the application (Figure 7). This use case exercises the GEvent facility in the Google Maps API, which is used to assign action listeners to objects plotted on the map. A listener that responds to a mouse click on a marker is created in the createMarker function. The assignment is made using the following code. Note that the function created to handle the event populates the customer form using the DWR utility function DWRUtil.setValues, which assigns values to elements contained in the page that map to the name/values pairs defined in a JavaScript object. The event handler also opens an information window on the map that displays the selected customer's name and address (Figure 8).

GEvent.addListener(marker, "click", function() {
   // set the selected marker
   currentMarker = marker;
   // set form field values
   DWRUtil.setValues(customer);
   ...
   // open info window with customer
   // name and address
   marker.openInfoWindowHtml(...);
  });

In summary, there are six essential steps to set up both DWR and Google Maps or any other JavaScript mashup API in a Web application:

  1. Edit the web.xml file and copy the dwr.jar file to the WEB-INF/lib directory.
  2. Create the Java objects that will be exposed remotely as JavaScript interfaces.
  3. Enable DWR to expose objects and methods remotely by defining a dwr.xml file.
  4. Acquire an activation key.
  5. Import all JavaScript files into your JSP pages.
  6. Finally, write a little JavaScript. Go on it's not so bad!
Conclusion
In this article you learned how to integrate Java services with mashup APIs implemented in JavaScript. The DWR framework enabled this simple integration by providing remote access to server-side Java objects via JavaScript. The value of this example is that it illustrates the simplicity of incorporating services implemented in either Java or JavaScript in the context of an enterprise-ready application. Thus, we now have one of the tools necessary to build an enterprise mashup. Next time, we'll look at how to consolidate the JavaScript code that comprises your mashup application into components that can be reused in a variety of development environments. For more information on the technologies referenced in this article please refer to the references provided.

References

About Ric Smith
Ric Smith is director, business and product strategy at Kaazing. provides Kaazing Corporation with a wealth of experience in product management and consulting for enterprise products and services. Prior to joining Kaazing, Ric was a principal product manager for Oracle's Fusion Middleware at Oracle's Headquarters in Redwood Shores, CA. In his role as a Principal Product Manager he was responsible for the evangelism and product direction of Oracle's AJAX and Java EE Web Tier offerings. Before joining the Fusion Middleware team, Ric worked for Oracle's consulting business as a principal consultant where he led development of mission-critical applications for prominent organizations within the defense/intelligence industry. In addition, Ric won consecutive awards for technical achievement for each year of his tenure as a consultant. Ric is a frequent speaker at international events and has written articles featured in leading industry publications such as Java Developer's Journal and AJAXWorld Magazine. He is also a representative to the OpenAjax Alliance and an honors graduate of the University of Arizona.

LATEST JAVA STORIES & POSTS
What's the key to team and individual developer productivity in maintaining and extending a large application? Let’s start by making the following assertions: A developer's knowledge of an application code base is likely the single biggest factor of individual productivity. Cor...
An applet, a Java program that runs in a browser, often has to access the client resources. However, the security manager prevents an applet from accessing client resources. To access client resources, the applet has to have the proper permission. With this permission the applet ...
Three-letter acronyms (TLAs) are hardly new in Information Technology: EAI, ESB, SOA, BPM, BAM, ETL, MDM; the list goes on and on. This article is about yet another three-letter acronym, EDA, which stands for Event-Driven Architecture. EDA is not a brand new technology, but rathe...
Furthering its dedication to providing Java developers productivity with choice, Oracle announced the Oracle Enterprise Pack for Eclipse, a new component of Oracle Fusion Middleware. This release marks the first free Eclipse 3.4 environment to support Oracle WebLogic Server 10g R...
Two of the biggest launches in Rich Internet Application history took place in 2007/2008 when Adobe launched AIR 1.0 in February '08 and Microsoft launched Silverlight (September '07). At the 6th International AJAXWorld RIA Conference & Expo in October SYS-CON Events is delighted...
Red Hat CTO Brian Stevens, Citrix CTO Simon Crosby, Egenera CTO Pete Manca, Allen Stewart, Group Manager, Windows Virtualization at Microsoft, and Brian Duckering, Sr. Director of Products and Alliances at Symantec were the top industry executives who joined Jeremy Geelan in the ...
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021


SYS-CON FEATURED WHITEPAPERS

SPONSORED BY INFRAGISTICS
There are many forces that influence technological evolution. After a decade of building enterprise ...
2008 is going to be an important year for Rich Internet Applications. Most organizations are deliver...
The OpenAjax Alliance is developing an Ajax industry wishlist for future browsers, using a dedicated...
In every field of design one of the first things students do is learn from the work of others. They ...
Infragistics announced the availability of two Community Technology Preview (CTP) User Interface (UI...
The YUI development team has released version 2.5.2; you can download the new release from SourceFor...
ADS BY GOOGLE
BREAKING JAVA NEWS

SpringSource, a leading provider of infrastructure software and the company behind ...