|
|
YOUR FEEDBACK
Did you read today's front page stories & breaking news?
SYS-CON.TV |
TOP THREE LINKS YOU MUST CLICK ON Trends
A New Weapon in Developing Rich Client Applications
Communicating JavaFX with EJB 3.0 Technology
By: Sonny Hastomo
Dec. 25, 2007 01:30 PM
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 can get the information on installing the JavaFX plug-in at https://openjfx.dev.java.net/javafx-nb55-plugin-install.html. Server Scenario 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 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: 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: 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 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 1. Create a JavaFX Project 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 3. Implement client script 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 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 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 LATEST JAVA STORIES & POSTS
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK BREAKING JAVA NEWS
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||