YOUR FEEDBACK
E-Commerce 2.0
Brian wrote: I think we're heading in the right direction, but we've still...
SOA World Conference
Virtualization Conference
$200 Savings Expire May 16, 2008... – Register Today!

2007 West
GOLD SPONSORS:
Active Endpoints
Your SOA Needs BPEL for Orchestration
BEA
Virtualized SOA: Adaptive Infrastructure for Demanding Applications
Nexaweb
Overcoming Bandwidth Challenges with Nexaweb
TIBCO
What is Service Virtualization?
SILVER SPONSORS:
WSO2
Using Web Services Technologies and FOSS Solutions
Click For 2007 East
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


A New Weapon in Developing Rich Client Applications
Communicating JavaFX with EJB 3.0 Technology

Digg This!

Page 2 of 2   « previous page

In this article we'll try to build a simple client application using JavaFX technology using the Netbean 5.5 editor, and this scripting client will communicate with EJB 3.0 technology that resides in the Sun Java Application Server 9 to provide the business functionality.

Prerequisite
You'll need Netbean 5.5 and the Sun Java Application Server 9 SDK installed on your operating system. You can download the first at http://www.netbeans.org/download/ and the other at http://java.sun.com/javaee/downloads/.

You can get the information on installing the JavaFX plug-in at https://openjfx.dev.java.net/javafx-nb55-plugin-install.html.

Server Scenario
Now that you've installed the software required, we'll try to build the EJB module with the Netbean Editor. If you're already familiar with EJB 2.1, you'll see that EJB 3.0 will cut the time window for coding process. Follow the steps bellow to develop and deploy the EJB component:

1.  Create an EJB Module Project
Click File -> New Project, choose the Enterprise category, and select the EJB Module under the projects selection list (see Figure 1).

Click Next -> assign the project name ServerModule, and don't forget to select the server for the Sun Java Application Server with Java EE Version 5.0 (see Figure 2).

Click Finish -> you'll see the new project created under the left pane of the Netbean 5.5 editor.

2.  Implement the business process code in the EJB component
In this step we'll create an EJB component called ServerUtility; this class will provide two EJB methods. The first method is getServerDate, which is serve the client to get the server date and formats the date in a "dd MMMM yyyy" pattern, and the second method is currentAge with birthdays as an input parameter; this method will provide the functionality to calculate your current age based on your birthday against the server date.

To create the EJB component you can select the Source Packages on the ServerModule project -> Right Click -> New -> Session Bean, Netbean Editor will prompt you with a form to fill in the specification parameters for the new EJB component that will be created such as EJB Name, packages, Session Type, and Create Interface. In our example we'll use the parameters:

a.  EJB Name -> ServerUtility
b.  Package -> org.sofu.ejb
c.  Session Type -> Stateless
d.  Create Interface -> Remote

The code in Listing 1 below will be automatically generated by the Netbean 5.5 Editor, and shows the EJB 3.0 capable of using the annotation to define the session type and the other definition parameters that were previously defined only by the ejb-jar.xml file. EJB 3.0 also offers some other features to ease the development effort; this is a list of the enhancements in EJB 3.0 in general:

  •   Simplified bean classes
  •   Environment access by using annotation or XML
  •   Dependency injection capability
  •   Dynamic environment lookup

If you're interested in finding out more about EJB 3.0 development you can visit Sun Microsystems' Web site at http://java.sun.com. There are a lot of articles there regarding the EJB 3.0 technology.

Now we'll write our method inside the ServerUtilityBean Java code as mention above by right-clicking the ServerUtilityBean code à EJB Method à Add Business Method à. You'll be prompted to supply the method specification such as method name, return type, method parameters, and exceptions. This utility for creating EJB Methods using Netbean will simplify writing the business method; it automatically generates the method skeleton in the remote interface. Two business method implemented in the EJB Bean class are shown in Listing 2.

3.  Deploy ServerModule to the Sun Java Application Server 9.0 Platform Edition
Right-click the ServerModule project -> Deploy Project ->. This process will automatically start the Sun Java Application Server 9.0 and deploy the EJB module to the application server. To verify whether the module deployed successfully, you can move to the runtime tab and check the ServerModule entity under the EJB modules folder (see Figure 3).

Albert Einstein said, "Things should be made as simple as possible - but no simpler." That statement in mind, system designers and developers tend to avoid the complexity of the software development process lifecycle. They think that simplicity is the most elegant way of doing things. In my opinion the fundamental measure of technology innovation is making things simpler. The enhanced EJB Framework and automated utility in the Netbeans Editor makes the perfect match of collaboration that push to simplicity of development process lifecycle.

Client-side Scenario
The implementation of an EJB component on the server platform has been done; now we'll concentrate on developing the client user interface by using JavaFX scripting technology. The following steps will guide you in developing the clients:

1.  Create a JavaFX Project
Click File -> New Project, choose JavaFX, and select JavaFX Application under the projects selection list (see Figure 4).

Click Next -> set the project name as JavaFXTeller (see Figure 5).

Click Finish -> you'll see the new JavaFX project created.

2.  Create gateway code to communicate between JavaFX and the EJB module
To keep the client code simple in accessing the EJB component we'll have to develop simple Java code that acts as a helper or gateway between the client and the server. The code is shown in Listing 3.

3.  Implement client script code
The simplicity of integrating the Java library using JavaFX is one of the advantages offered by this technology. The code example in Listing 4 shows us how to import the Java library and create a class in JavaFX script client code.

In this code you'll see that we put all the client user interfaces that attach to the frame in the attribute client window such as Text, View, FlowPanel, and Canvas. The purpose is to make the script codes more systematic and easy to read rather than put the script code in a continuous form.

The code in Listing 5 shows us how to create an instance of the Command object, that is an object written in Java code as a gateway to access the EJB component residing on the server platform. These lines of code also describe how to create a window instance and how to set the attribute from the window object such as the frame width and height.

As we observe those lines of code we have done build button component and assign it to the clientBtnAttribute on window object, and we implement the action should be done when the button pressed. The cmdCurrentAge will proxy the currentAge method under the ServerUtility EJB component on the server platform. And, as you'll notice from the Command.java code implemented in Listing 6, we need to define the server environment on the gateway code such as PROVIDER_URL, URL_PKG_PREFIXES, and so on, which provides basic information for accessing the EJB module on the server platform.

In Listing 7 we try composing the UI component in the canvas attribute and put the canvas into the FlowPanel (clientPanel). The clientPanel attribute will be assign to the content of the Frame that's the main window in displaying the client form.

4.  Run the JavaFX application
Right-click the ClientModule Project -> Run Project ->. You'll see the window client in Figure 6.

You'll see the EJB module to get the server date invoked from the JavaFX client script via the Command object. If we fill up the textbox with the "dd/MM/yyyy" format and press the "Calculate My Age" button you'll see how old are you now has been stayed on Planet Earth (see Figure 7).

Summary
JavaFX's capacity for interacting with Java code makes client script technology perfect for developing rich client applications that communicate with any existing Java application either as a server platform component or as purely a Java library utility. The diagram below shows the flexibility of accessing a EJB module on the server platform directly or through a custom proxy library (see Figure 8).

Generally speaking JavaFX script client technology provides a new weapon for developing rich client applications that are fully integrated with Java, and in my opinion push this technology to the next level by focusing on the human side of code development such as code pattern and user-friendly UI building.


Page 2 of 2   « previous page

About Sonny Hastomo
Sonny Hastomo is an IT architect at Sun Microsystems, Indonesia, for the telecommunication industry division. His currently is focusing on providing solution design, sizing, implementation, consulting services, and quality support to customers in their evaluation of their IT challenges.

LATEST OPEN WEB DEVELOPER STORIES
Verizon Becomes a Counter-Android Linux Convert
Verizon Wireless is snubbing Google's Linux-based Android initiative to go with the LiMo Foundation's mobile Linux spec for its next wave of mobile phones expected next year. Along with Verizon, Mozilla signed up - giving the consortium its first major open source ISV - and a key
Zoho Invites Google & Yahoo Users to Login
Zoho announced that it is welcoming Google and Yahoo users with a unified login designed to encourage those users to try Zoho applications. Now, Google and Yahoo users who visit Zoho can simply log into Zoho using the usernames and passwords associated with their Google and Yahoo
Enterprise Web Security Added to Google Apps
Google has taken its Postini investment and turned out Google Web Security for the Enterprise, which is supposed to protect against spyware, viruses and zero-hour threats in real-time whether the user is on the corporate network or working remotely like at a hotel or in an airpor
Borland Finally Dumps CodeGear Tools Division
It's only taken Borland two years but it's finally dumped its CodeGear tools division, responsible for Borland's hereditary JBuilder, Delphi and C++ Builder lines as well as its new web ventures into PHP and Ruby, said to be used by 7.5 million developers. Embarcadero Technologie
Microsoft, Unisys, Yahoo and Vista
Microsoft, which spent $6 billion on aQuantive and was chasing Yahoo for its ads before it came to a dead stop, has been supporting - as in helping write - legislation in New York and Connecticut that would regulate the data that companies like Yahoo and Google collect for target
Yahoo! How Like the Virgin Mary!
So how does it feel to have witnessed one of technology's little miracles this week? I mean Yahoo's stock price successfully defying gravity. It's as close as any of us will ever get to an apparition of the Virgin Mary floating on a cloud without any visible means of support. App
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

ADS BY GOOGLE
BREAKING OPEN WEB DEVELOPER NEWS
DeepOcean Board Recommends Acceptance of Mandatory Offer From Trico
Trico Marine Services, Inc. (NASDAQ: TRMA)