Welcome!

Java Authors: Esmeralda Swartz, Trevor Parsons, Paul Speciale, Lori MacVittie, Sandi Mappic

Related Topics: Java, ColdFusion, Adobe Flex

Java: Article

Rich Internet Applications with Adobe Flex 2 and Java

Flash + POJO = RIAs

A typical Java developer knows that when you need to develop a GUI for a Java application, Swing is the tool. Eclipse SWT also has a number of followers, but the majority of people use Java Swing. For the past 10 years, it was a given that Swing development wouldn't be easy; you have to master working with the event-dispatch thread, GridBaglayout, and the like. Recently, the NetBeans team created a nice GUI designer called Matisse, which was also ported to MyEclipse. Prior to Matisse, JBuilder had the best Swing designer, but it was too expensive. Now a good designer comes with NetBeans for free.

Why even consider Flex for developing Rich Internet Applications (RIA)? First, we'll give the short answer. Just look at the code in Listing 1. This code compiles and runs in the Flash player and produces the output shown in Figure 1. Yes, it's a tree control with several nodes that know how to expand, collapse, and highlight the user's selection. Imagine the amount of Java code you'd need to write to achieve the same functionality.

The code is nice and clean; the GUI looks rich and appealing. The Flex compiler automatically converts the MXML code in Listing 1 into an object-oriented language called ActionScript, and then compiles it into an SWF file, the format that the Flash player understands.

To add the business processing to this example, we'd need to write event handlers in the ActionScript 3.0 language, which is very similar to Java, but we wouldn't have to worry about routing all events to the event-dispatch queue. Below are some of the other reasons that the Flex/Flash combination is a very promising technology for RIA development:

  • The Flash player, a powerful virtual machine with a high-performing byte code/JIT compiler and rich UI API, is available on most of the platforms.
  • The size of the VM is small.
  • It easily integrates with Web browsers.
  • Flash applications can run outside of the Web browser.
  • Flex offers component-based programming, which eliminates most of the low-level coding.
  • It offers simple integration with all kinds of media (video and audio). Java Swing is behind in this field.
  • It has a quick adoption rate as all other Adobe products.
  • Most important, Flex 2 easily integrates with Java on the server side.
Later in this article we'll develop a Stock Portfolio Application with Flex, and then we'll integrate it with POJOs.

Flex client applications are compiled SWF files that can be delivered to the client and run by the Flash player, which is installed as a plug-in to your browser. On the client side, Flex consists of a Flash player, a framework of predefined components, a couple of command-line compilers, and an Eclipse-based Flex Builder IDE. On the server side, Flex is a Web application that includes Flex Data Services and a Flex Charting component and can be deployed in any JEE server.

To see Flex in action, let's write the functional specification, then develop and deploy a sample application.

Designing the Stock Portfolio Application
We'll create a Web application that will receive and display a feed containing security prices and the latest news as in Figure 2 and 3.

The top portion of the screen must be populated by the stocks included in the user's portfolio. For simplicity, store the user's portfolio in the XML file as in Listing 2.

When the user clicks on a row with a particular stock (i.e., ADBE as in Figure 2), populate the lower data grid with the headlines related to the selected stock. The news should be coming from http://finance.yahoo.com/rss/headline. The column link has to contain the URLs of the news, and when the user clicks on the link, a new browser's window should pop up displaying the selected news article.

The top of the screen should contain the toggle buttons Show Grid/Show Chart. When the Show Grid option is selected, the user will see the screen as in Figure 2, and when Show Chart is selected, the top data grid has to be replaced with the pie chart (see Figure 3), preserving the same functionality (clicking on the pie slice repopulates the news headlines).The market data has to be refreshed on the screen every second or so.

Since we are limited by the size of this article, for the server side we'll just write a simple POJO that will generate random numbers and push them back to the Flash client. However, in the next article we'll add the data feed from an external Java application via JMS.

Sounds like an ambitious task for a short magazine article, doesn't it? This article is not a tutorial on Flex MXML or ActionScript, but as a Java developer, you should be able to understand how the code is put together with minimal explanations. After deploying and running this application  you can study Flex more formally. So let's roll up our sleeves...

Installing Flex Builder and Flex Data Services
At the time of this writing, Flex 2 is still in beta (http://labs.macromedia.com/flexproductline/ ) and its production release is expected this summer. The burning question is, "Is it free?" The answer is, "It depends." There is a free lunch (or rather a complimentary appetizer from the chef), but it'll just whet your appetite, and pretty soon your hand will start slowly reaching for the wallet. Flex Data Services (FDS) that provide seamless integration of Flex into enterprise data and messaging have deployment fees. For high-performance enterprise applications supporting client authentication, messaging, and the like, you may want to purchase the FDS license. For smaller applications, you might use integration via HTTPService, Web Services, and Remote Java invocation using standard and open source technologies.

The free part is Flex command-line compilers and the Flex framework that includes all these libraries of rich components. This means you can use any plain text editor for writing Flex code, compile it into the SWF file, and run it in a free Flash 9 player. As of today though, Adobe says that the Eclipse-based Flex Builder IDE, which makes development a lot more productive, will not be free. Flex Charting components that offer client-side interactive charts are not free either.

The Flex Builder IDE comes in two flavors: a standalone version and the Eclipse plug-in. You'll have to choose one of these versions during the installation process. Let's install Eclipse 3.1 first from www.eclipse.org/downloads/ (unless you have it already), and then the plug-in version of Flex Builder. During the installation, you'll have to specify the directory where your Eclipse resides (the one that has a subdirectory called plug-ins). After Flex Builder is installed, start the Eclipse IDE, select the menus Window | Open Perspective | Other and add the Flex Development perspective (the Flex Debugging perspective will be added automatically to the Eclipse IDE). The Flex Builder comes with great Help content, which in the plug-in version is hidden under the menu Help | Help Contents | Adobe Help.

To run client-only Flex applications, we need to install one more program: Flash Player 9. However, for our stock portfolio application, we'll need to install and deploy FDS, which is a Web application that can be deployed in any JEE compliant container. Since FDS is a Web application, you can deploy it in the application server of your choice. First, we'll download and install Apache Tomcat 5.5 from http://tomcat.apache.org/. By default, on Windows machines Tomcat is installed in "C:\Program Files\Apache Software Foundation\Tomcat 5.5" and runs on port 8080. At the end of the installation, the Apache Tomcat server will be started as a Windows service. Now download from and run the FDS executable installer (default directory ID C:\fds2), picking the optional Flex Data Services J2EE Application. After the installation is finished, unzip the content of the flex.war into Tomcat's webaps\ROOT directory and restart the Apache Tomcat service. Enter the URL http://127.0.0.1:8080/ in your browser, and you should see the FDS Welcome screen. Flex Data Services are deployed now under Tomcat.

Developing Stock Portfolio Application with Flex
What Runs Where
First, let's see which components will run on the client and what belongs to the Web server. The code shown in Listings 3-6 will be compiled into portfolio.swf, which will run on the client either independently in the Flash 8.5 player, or with the help of portfolio.html (auto-generated by Flex Builder) in the Web browser with the Flash plug-in. Tomcat is our server, which will host compiled Java classes shown in Listings 7 and 8. We'll also make small additions in the server configuration files (see Listings 9 and 10) to specify where to find the Java classes and to allow access to the external Yahoo! service. While Flex provides different ways of client/server communication (RemoteObjects, HTTPService, WebService), in this article our client will use the RPC by means of the <mx:RemoteObject> component that will find the matching Java classes located and configured on the server as described at the end of this article.

Developing the GUI Part
Open the Flex perspective in Eclipse and create a new project (e.g., Portfolio_RCP) containing files from Listings 3-7, and then compile it into one file called portfolio.swf. To simplify deployment, set the project's output directory to Tomcat's \ROOT\portfolio.

Our main file portfolio.mxml (see Listing 3) divides the screen with the vertical Flex box-type layout (<mx:VDividedBox>) with an adjustable divider between its children (think of Swing's split panes), and it includes two separate code fragments. The bottom child contains a data grid programmed in <FinancialNews> (see Listing 6). The top child contains <PortfolioView> (see Listing 4).

Java developers know that some Swing components store the data and GUI parts separately, for example, the JTable gets its feed from a data model class that can store its data in a Java collection. On a similar note, some Flex controls (e.g., <mx:DataGrid>) can also use ActionScript collection classes as data providers. Our data model is the file portfolio.xml depicted in Listing 2.

This code represents a typical master-detail relationship, where a change in the selected security in the master component <PortfolioView> repopulates the detail component <FinancialNews>.

Getting the Price Quotes
Let's go over some interesting programming techniques that we've applied while coding the top panel, which contains several Flex framework components wrapped into a Canvas container (see Listing 4). After learning that the user's portfolio is represented by portfolio.xml, you may expect at least some number of lines performing XML parsing.

What do you think of this line:

<mx:XML format="e4x" id="portfolioModel" source="portfolio.xml" />

The XML parsing is complete! After this line you can traverse the entire XML document using a simple dot notation, e.g., portfolioModel.security. This magic is possible because Flex supports the e4x format that was introduced by W3C as a simple alternative for reading and processing XML documents.

Another interesting feature to comment is data binding, which is a way to link the data in one object to another. In particular, it's a convenient way to move the data between the GUI and non-visual components. Data binding can be specified using the curly braces syntax. The following lines from Listing 4 provide an immediate refresh of the top data grid and chart as soon as the data in the underlying security changes.

<mx:DataGrid id="portfolioGrid" width="100%" height="100%"
      dataProvider="{portfolioModel.security}"
<mx:PieChart id="portfolioPie" dataProvider="{portfolioModel.security}"

The variable portfolioModel.security represents the data source, and the destination will change as soon as any property of the source changes. Note that we have one data source mapped to two destinations (the data grid and pie chart), so we don't need to do any additional programming to refresh the data grid and the chart when the incoming market data changes the properties of the security.


More Stories By Victor Rasputnis

Dr. Victor Rasputnis is a Managing Principal of Farata Systems. He's responsible for providing architectural design, implementation management and mentoring to companies migrating to XML Internet technologies. He holds a PhD in computer science from the Moscow Institute of Robotics. You can reach him at [email protected]

More Stories By Yakov Fain

Yakov Fain is a co-founder of two software companies: Farata Systems and SuranceBay. He authored several technical books and lots of articles on software development. Yakov is Java Champion (https://java-champions.java.net). He leads leads Princeton Java Users Group. Two of Yakov's books will go in print this year: "Enterprise Web Development" (O'Reilly) and "Java For Kids" (No Starch Press).

More Stories By Anatole Tartakovsky

Anatole Tartakovsky is a Managing Principal of Farata Systems. He's responsible for creation of frameworks and reusable components. Anatole authored number of books and articles on AJAX, XML, Internet and client-server technologies. He holds an MS in mathematics. You can reach him at [email protected]

Comments (17)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


@ThingsExpo Stories
Samsung VP Jacopo Lenzi, who headed the company's recent SmartThings acquisition under the auspices of Samsung's Open Innovaction Center (OIC), answered a few questions we had about the deal. This interview was in conjunction with our interview with SmartThings CEO Alex Hawkinson. IoT Journal: SmartThings was developed in an open, standards-agnostic platform, and will now be part of Samsung's Open Innovation Center. Can you elaborate on your commitment to keep the platform open? Jacopo Lenzi: Samsung recognizes that true, accelerated innovation cannot be driven from one source, but requires a...
SYS-CON Events announced today that Red Hat, the world's leading provider of open source solutions, will exhibit at Internet of @ThingsExpo, which will take place on November 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. Red Hat is the world's leading provider of open source software solutions, using a community-powered approach to reliable and high-performing cloud, Linux, middleware, storage and virtualization technologies. Red Hat also offers award-winning support, training, and consulting services. As the connective hub in a global network of enterprises, partners, a...
P2P RTC will impact the landscape of communications, shifting from traditional telephony style communications models to OTT (Over-The-Top) cloud assisted & PaaS (Platform as a Service) communication services. The P2P shift will impact many areas of our lives, from mobile communication, human interactive web services, RTC and telephony infrastructure, user federation, security and privacy implications, business costs, and scalability. In his session at Internet of @ThingsExpo, Robin Raymond, Chief Architect at Hookflash Inc., will walk through the shifting landscape of traditional telephone a...
SYS-CON Events announced today that Matrix.org has been named “Silver Sponsor” of Internet of @ThingsExpo, which will take place on November 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. Matrix is an ambitious new open standard for open, distributed, real-time communication over IP. It defines a new approach for interoperable Instant Messaging and VoIP based on pragmatic HTTP APIs and WebRTC, and provides open source reference implementations to showcase and bootstrap the new standard. Our focus is on simplicity, security, and supporting the fullest feature set.
BSQUARE is a global leader of embedded software solutions. We enable smart connected systems at the device level and beyond that millions use every day and provide actionable data solutions for the growing Internet of Things (IoT) market. We empower our world-class customers with our products, services and solutions to achieve innovation and success. For more information, visit www.bsquare.com.
How do APIs and IoT relate? The answer is not as simple as merely adding an API on top of a dumb device, but rather about understanding the architectural patterns for implementing an IoT fabric. There are typically two or three trends: Exposing the device to a management framework Exposing that management framework to a business centric logic • Exposing that business layer and data to end users. This last trend is the IoT stack, which involves a new shift in the separation of what stuff happens, where data lives and where the interface lies. For instance, it’s a mix of architectural style...
SYS-CON Events announced today that SOA Software, an API management leader, will exhibit at SYS-CON's 15th International Cloud Expo®, which will take place on November 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. SOA Software is a leading provider of API Management and SOA Governance products that equip business to deliver APIs and SOA together to drive their company to meet its business strategy quickly and effectively. SOA Software’s technology helps businesses to accelerate their digital channels with APIs, drive partner adoption, monetize their assets, and achieve a...
From a software development perspective IoT is about programming "things," about connecting them with each other or integrating them with existing applications. In his session at @ThingsExpo, Yakov Fain, co-founder of Farata Systems and SuranceBay, will show you how small IoT-enabled devices from multiple manufacturers can be integrated into the workflow of an enterprise application. This is a practical demo of building a framework and components in HTML/Java/Mobile technologies to serve as a platform that can integrate new devices as they become available on the market.
SYS-CON Events announced today that Utimaco will exhibit at SYS-CON's 15th International Cloud Expo®, which will take place on November 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. Utimaco is a leading manufacturer of hardware based security solutions that provide the root of trust to keep cryptographic keys safe, secure critical digital infrastructures and protect high value data assets. Only Utimaco delivers a general-purpose hardware security module (HSM) as a customizable platform to easily integrate into existing software solutions, embed business logic and build s...
Connected devices are changing the way we go about our everyday life, from wearables to driverless cars, to smart grids and entire industries revolutionizing business opportunities through smart objects, capable of two-way communication. But what happens when objects are given an IP-address, and we rely on that connection, sometimes with our lives? How do we secure those vast data infrastructures and safe-keep the privacy of sensitive information? This session will outline how each and every connected device can uphold a core root of trust via a unique cryptographic signature – a “bir...
Internet of @ThingsExpo Silicon Valley announced on Thursday its first 12 all-star speakers and sessions for its upcoming event, which will take place November 4-6, 2014, at the Santa Clara Convention Center in California. @ThingsExpo, the first and largest IoT event in the world, debuted at the Javits Center in New York City in June 10-12, 2014 with over 6,000 delegates attending the conference. Among the first 12 announced world class speakers, IBM will present two highly popular IoT sessions, which will take place November 4-6, 2014 at the Santa Clara Convention Center in Santa Clara, Calif...
Almost everyone sees the potential of Internet of Things but how can businesses truly unlock that potential. The key will be in the ability to discover business insight in the midst of an ocean of Big Data generated from billions of embedded devices via Systems of Discover. Businesses will also need to ensure that they can sustain that insight by leveraging the cloud for global reach, scale and elasticity.
WebRTC defines no default signaling protocol, causing fragmentation between WebRTC silos. SIP and XMPP provide possibilities, but come with considerable complexity and are not designed for use in a web environment. In his session at Internet of @ThingsExpo, Matthew Hodgson, technical co-founder of the Matrix.org, will discuss how Matrix is a new non-profit Open Source Project that defines both a new HTTP-based standard for VoIP & IM signaling and provides reference implementations.

SUNNYVALE, Calif., Oct. 20, 2014 /PRNewswire/ -- Spansion Inc. (NYSE: CODE), a global leader in embedded systems, today added 96 new products to the Spansion® FM4 Family of flexible microcontrollers (MCUs). Based on the ARM® Cortex®-M4F core, the new MCUs boast a 200 MHz operating frequency and support a diverse set of on-chip peripherals for enhanced human machine interfaces (HMIs) and machine-to-machine (M2M) communications. The rich set of periphera...

SYS-CON Events announced today that Aria Systems, the recurring revenue expert, has been named "Bronze Sponsor" of SYS-CON's 15th International Cloud Expo®, which will take place on November 4-6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. Aria Systems helps leading businesses connect their customers with the products and services they love. Industry leaders like Pitney Bowes, Experian, AAA NCNU, VMware, HootSuite and many others choose Aria to power their recurring revenue business and deliver exceptional experiences to their customers.
The Internet of Things (IoT) is going to require a new way of thinking and of developing software for speed, security and innovation. This requires IT leaders to balance business as usual while anticipating for the next market and technology trends. Cloud provides the right IT asset portfolio to help today’s IT leaders manage the old and prepare for the new. Today the cloud conversation is evolving from private and public to hybrid. This session will provide use cases and insights to reinforce the value of the network in helping organizations to maximize their company’s cloud experience.
The Internet of Things (IoT) is making everything it touches smarter – smart devices, smart cars and smart cities. And lucky us, we’re just beginning to reap the benefits as we work toward a networked society. However, this technology-driven innovation is impacting more than just individuals. The IoT has an environmental impact as well, which brings us to the theme of this month’s #IoTuesday Twitter chat. The ability to remove inefficiencies through connected objects is driving change throughout every sector, including waste management. BigBelly Solar, located just outside of Boston, is trans...
SYS-CON Events announced today that Matrix.org has been named “Silver Sponsor” of Internet of @ThingsExpo, which will take place on November 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. Matrix is an ambitious new open standard for open, distributed, real-time communication over IP. It defines a new approach for interoperable Instant Messaging and VoIP based on pragmatic HTTP APIs and WebRTC, and provides open source reference implementations to showcase and bootstrap the new standard. Our focus is on simplicity, security, and supporting the fullest feature set.
Predicted by Gartner to add $1.9 trillion to the global economy by 2020, the Internet of Everything (IoE) is based on the idea that devices, systems and services will connect in simple, transparent ways, enabling seamless interactions among devices across brands and sectors. As this vision unfolds, it is clear that no single company can accomplish the level of interoperability required to support the horizontal aspects of the IoE. The AllSeen Alliance, announced in December 2013, was formed with the goal to advance IoE adoption and innovation in the connected home, healthcare, education, aut...
SYS-CON Events announced today that Red Hat, the world's leading provider of open source solutions, will exhibit at Internet of @ThingsExpo, which will take place on November 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. Red Hat is the world's leading provider of open source software solutions, using a community-powered approach to reliable and high-performing cloud, Linux, middleware, storage and virtualization technologies. Red Hat also offers award-winning support, training, and consulting services. As the connective hub in a global network of enterprises, partners, a...