Home  >  

Pet Store with JavaFX 1.0. Part 1.

Author photo
| | Comments (9)
AddThis Social Bookmark Button

I work for a company called Farata Systems. Laura is our office manager, and she doesn’t know Java. Everyone else does. We work in the enterprise RIA space using Adobe Flex as a main development tool for creating all these Web pages connecting to the server side applications written in Java.

In December of 2008, Sun Microsystems has released the first version of a language for developing UI for RIA. I’ve been watching the evolution of JavaFX from its announcement at JavaOne 2007 till its release, but wasn’t able to find any demos that would prove that this extension of Java platform can be considered as a candidate for boring needs of enterprise applications. Watching demos like a bunch of balls moving inside a glass didn’t look too convincing to me.

We decided to contribute to Java community and invest some time and resources to figure out what JavaFX 1.0 is capable of. Most of the Java developers know what Pet Store application is. For many years this reference implementation has been used by Sun Microsystems as a part of Java BluePrints program for Java EE platform.

The current version of this application is described in the article called “Introducing the Java Pet Store 2.0 Application” that’s available at http://java.sun.com/developer/technicalArticles/J2EE/petstore/.

We re-used the existing back end of the Pet store, but performed a little facelift by replacing the UI developed with AJAX/JSP/JavaServer Faces with JavaFX 1.0.

I was working on this project with our senior Java developer Alex Litskevich who’s done lots of digging and research trying to find the best solutions whenever we would run into limitations of JavaFX.
The goal of this introductory article is to demo the JavaFX Pet Store. You can watch a quick prerecorded demo at this URL .

In the future, I’ll deploy this application in one of our public servers and will review the code.

Last year, while attending a conference in India, I met an excellent Sun’s software engineer Greg Murray, one of the authors of the idea of Pet Store application. Greg, I hope you’ll like this version of your pet store.

Flex, JavaFX, Silverlight…

I’ll be honest with you, during development of this application in the back of my mind I’ve been constantly comparing the way things are done in JavaFX with how I’d do the same with Adobe Flex.
Simply put, today, Flex is a lot more productive than JavaFX. But let’s remember that we are comparing products of versions 3 vs. version 1. If you know how to develop Swing applications, you might want to continue doing this rather than manually creating JavaFX 1.0 wrappers for Java code as we did in our Pet Store.

The biggest issue is that JavaFX 1.0 doesn’t include any UI component library that a Web developer needs. I’m not talking about data grids or tree views. Even such simple things as a hyperlink component aren’t there. I can’t think of any other reason but a trivial lack of time and limited human resources allocated by Sun for development of this new UI set.

Hopefully, Sun will release a JavaFX 2.0 in foreseeable future with a full set of UI components, containers, navigators, and layouts. Just to draw an analogy, Microsoft has released absolutely naked Silverlight 1.0 in 2007, but full featured Silverlight 2.0 became available a year after.
The good news is that Java developers have already started building their own open source components for JavaFX. The name of this project is jfxtras .

On the other hand, I see some features available for JavaFX developers that are missing in Flex.

For example, ActionScript doesn’t support multi-threading. This is not an issue when it comes to communication with remote sites - all remote calls are asynchronous and use callbacks for server-to-client data flows. But if you’d need to write or use an existing Java library that performs some CPU-intensive calculations on the client, I’m sure Java will beat ActionScript. The syntax of both languages is pretty similar though (see http://flexblog.faratasystems.com/?p=115).
JavaFX supports eval() function that allows to compile and execute a piece of code on the fly. Flex doesn’t support this useful feature.

Two-way binding already exists in JavaFX but in Flex will get it only in version 4.

I’ve yet to see some benchmarks comparing Flex and JavaFX network protocol. The latter just offers XML and REST for data exchange between client and server. Of course, you can program Java sockets or wrap up an RMI client into JavaFX - would it be faster than ActionScript Real-Time Messaging Protocol? We don’t know. Or take HTTP tunneling between Java Applet and a server-side Java stream. Would it be faster than using AMF, an HTTP-based binary protocol? We don’t know yet.

JavaFX removes a lot of complications in developing mobile applications. It promises to remove the need of using Java SE for desktop and Java ME for mobile - JavaFX should be the only solution you need. JavaFX Mobile offers hardware acceleration. Keep in mind, there are 2.6 billion of Java enabled mobile devices! JavaFX has serious advantage in this domain over Flash Lite.

JavaFX 1.1 is about to be released. It offers performance improvements, bug fixes, new features in the mobile space, but no major additions to the desktop platform.

I understand that this is not a good time to ask for some serious cash injections, but if executives of Sun Microsystems won’t find a way to double the size of the team working on the future version of JavaFX, entire Adobe Flex team can safely go on sabbatical for a year. If the money is tight, the sooner JavaFX will go open source, the better.

Even though I wouldn’t start developing with JavaFX a project that needs to go in production this year, overall, JavaFX looks promising. Try it out and see for yourself.

Read more from Yakov Fain. Yakov Fain's Atom feed

Comments

9 Comments

Glimes said:

Hello,

This article is very interesting. But I want to See some code...

I'm a newbie in Java, and I don't understand how we can bind a javaFx properties with a old java bean. Is it possible?

For exemple, if I create a bean in a java class with a private Integer field, constructor, getter, setter, toString in a java class and a addOne method.

I can create a variable in fx=> var count:test = new Test("1");

Then I have a label with a text bind =>text: bind count.toString()

If I have a buton who call the addOne method the label is never updated, but the Integer in the bean is. (a simple sysout in the consol of this integer when I call addOne).

Can you please open my eyes to know how to 'update' this label?

Sory but you are the only one I see who make something like I want to do with FX. I want to re-use my bean i worked with Hibernate for the mapping with a DB.

Thanks,

Christophe.

Jim said:

Yakov,

Thanks for the review and demo. I'm curious to hear more about your comparison of Silverlight 2.0 to Flex. Also, I have yet to hear anyone answer if JavaFX's media player is capable of supporting streaming content (eg. Adobe FMS or MS Media Services, or open source).

--Jim

Yakov Fain said:

I've compared JavaFX 1.0 to Silverlight 1.0 - both were not ready for enterprise development. Silverlight 2.0 has a lot more than JavaFX 1.0.

I don't know about FMS, but I doubt it.

kamis said:

ok, I play with flex for a year now or more, mxml is a pain in @#$, it is nice when you do something simple, but if you want to create something sophisticated prepare yourself for headache.

what about invoking host's programs, connecting to db as desktop app. AIR cant (yes we have sqlite), it is limited only to hard drive. Installing any Air application it is some nightmare. For jfx only the process of installing plugin and environment is more complicated, but then upload jar with jnlp and you r done. and you have normal html link. nice!

What is missing right now for me is custom preloader but maybe it will change.

from my point of view most important is that developer dont need to touch any gimp or PS to create good looking view element. for flex you need use pure actionscript (what is hard) or libs like degrafa.

lastly I hope that plugin for netbeans will improve.

take care

Yakov Fain said:

Finishing writing a chapter on AIR for a new book Enterprise Development with Flex. Didn't experience any nightmare in installation and development of the application that's working with a local database and synchronizes the data with the remote DBMS. You may want to watch a short demo at http://flexblog.faratasystems.com/?p=394

But I agree, AIR 1.5 is not a full-fledged desktop development system such as Java. As to JavaFX 1.0, it's not ready for the prime time yet. Let's wait for 2.0.

kamis said:

"Installing any Air application it is some nightmare" I meant that as a developer I expect something simpler then another swf that you need to tweak before putting on you web page, and then user need to install it in the system (what for???) and then uninstall(it should all go to temp or cache like all other web content by default).

I agree that exchanging data with servers via AMF is straight forward, but hey we have spring framework and we can access even hibernate's lazy initialized beans without any problem(without all *-config.xml, ok just small one for spring)

for me AS3 is horrible language. ie. try manipulate dates from sqlite in AIR. no Date.fromstring(string, 'yyyy-mm-dd hh:nn:ss')? ok we have DateField but it accepts only date and not time, no rounding for number that could round to given decimal place, ok we can always try something with numberformatter but it is just silly.

:) ok I stop. take care

The full component package will be available in JavaFX 1.5, to be released soon in JavaOne. Considering that JavaFX 1.1 is already much more complete than Silverlight 1.0 was (Silverlight for Mobile is not available even in present day, JavaFX mobile is!), it seems that Sun is being fast enough in the cath-up game.

The feature holes that JavaFX still have force you to wrap around some Java code, but the other side of the coin is that you CAN easily wrap around some Java code, and tap into the enormous availability of Java APIs, open source projects, legacy code, etc. It's a big advantage, even though it's a portability tradeoff (e.g. using some JavaSE-specific API won't let the same code work in JavaFX Mobile#.

There's also a vast amount of Java tech that Sun can exploit in benefit of JavaFX. For one thing, XML-FI #FastInfoset - "binary XML") is strongly supported by JavaSE/EE's latest web service stacks, and JavaFX could use that easily (at least in the desktop). Much better move than Adobe's AMF which is yet another proprietary and half-baked format (XML-FI is an ISO standard, and strong tech overall). Adobe is already being forced to support Java-centric interop anyway (see BlazeDS) so we can just ignore Flash's crappy protocols. (Except of course audio/video ones; Flash is good there and JavaFX already copies the core of that good stuff like FLV support.)

Yakov Fain said:

I agree, eventually JavaFX will take an advantage of the huge code base available in Java. The main concerns are

1. Penetration of runtime - this is especiall important for the consumer facing applications. So far nothing is even close to the penetration of Flash Player, which is a VM.

2. Ease of the VM installation.

As to your negative comments about Flash protocols...BlazeDS is using AMF protocol too and it's not crappy. It remains to be seeing which protocol is faster. Let's wait and see.

Hamlet DArcy said:

@Osvaldo

>> Much better move than Adobe's AMF which is yet
>> another proprietary and half-baked format

Can you explain this more? I can't find any posts/research even comparing XML-FI to AMF. Flex doesn't seem to support XML-FI, so maybe that is why there is no comparison.

Leave a comment


Tag Cloud

Question of the Week: Dream App

If you had an unlimited budget and unlimited resources what application would you build and why would you build it?

Answer

Latest Features

Recommended for You

@InsideRIA on Twitter

Archives

  • Or, visit our complete archive.  

About This Site

Welcome to the premiere community site for all things RIA sponsored by O'Reilly Media and Adobe Systems Incorporated.