Rich Internet Applications

Java Development News:

Rich Internet Applications

By Vic Cekvinich

01 Aug 2004 | TheServerSide.com

  • Digg This
  • Stumble
  • Delicious

Hello World Rich Internet Application (RiA) Recipe

Background

This spring I completed a Friendster like site for Ziff-Davis to host 5 gaming magazines and 10 million members. Their old site was based on ASP and did not have Friendster like capabilities. (In between gigs, Google contacted me about a job but it did not pan out). Then I find out that Friendster's implementation of Java was poor and they switched to PHP, a bit of a black eye for the Java community that was discussed on TheServerSide.com. (Too bad they did not subcontract someone with production Java experience to help recover, not everyone “knows” Java hand on, some “know of” Java from books. This is why the Java community is sometimes perceived as “academic crap” )

Around this time, I began to realize that 80's technology such as HTML will go the way of the VT-100, as more and more people have broadband and larger screens, they want an MTV like experience. That's right, it makes no sense now to develop any HTML application that will be deployed in '05 and operated into '06. People are starting to expect rich content, such as january.rr.com/flash . HTML is legacy to me. Let's see.

I even held a seminar, where we talked about RiA, Rich Internet Applications (jroller.com/page/jcarreira/20040403 )
I also spent time writing Flex (by Neville), such as:


<mx:DataGrid  id="dg" dataProvider="{empD}"
  initialize="initSO()"
  cellPress="openDetail(dg.selectedItem.lname)"
  />

<mx:RemoteObject    id="empSO"  source="com.bPe.play.empDAO"
       result="empD=event.result"  />
<mx:Script> <![CDATA[
 var empD;
 function initSO() {
  empSO.populate();    }
    function openDetail( o ) {
 ldr.load();    }
</mx:Script>
<mx:Loader id="ldr" source="zoom.mxml.swf" autoLoad="false" />

This code creates a datagrid, loads it via a service object called empSO and on the cellPress event, opens a popup of the details for that row. The datagrid can sort on the client which is one of the features that makes this an RiA app. I found Flex slow to render for non-trivial forms, therefore not a good enough candidate for RiA.

Overview

Java Desktop (by Davidson) (JDNC) is one example of an Open Source RiA toolkit, but ... we are jumping ahead.

spacer

RiA applications get deployed via the Internet and execute on the user's desktop and provide a rich media experience. One example of a futuristic killer app is iTunes.

Grid sorting and rendering executes on the client, not the server. Also, the UI is not sent back and forth to the server with each request, only data is sent.

Ok, back to Java Desktop. Java Desktop is sponsored by Sun, and it's open source under LGPL (so Sun is slowly open sourcing Java). Please do not confuse this with poor old Swing. You might say, “What does Java Desktop have to do with the server side?”. Unlike Client/Server, there is no DLL hell and upgrades of the application are cheap and effective. What makes it superior to MS technologies is Network Launcher (JNLP – aka WebStart, the annoying icon that gets installed when you install the JDK). It's so easy to install, upgrade and deploy, that in no time at all your desktop could be filled with little Network Launcher icons (and dare I say, Java would then own the desktop, right?). So the Java Desktop is great – it can be deployed, managed and upgraded by a remote network server.

The other thing about iTunes is that the software is free. Users now expect software to be free. Thanks to Apache, Firebird, OpenOffice and the like, the precedent has been set. And while it's becoming increasingly difficult to charge for software, one can charge for usage (per transaction, per month, etc.) so monitoring the RiA/SoA applications becomes key. Not only monitoring for security and performance, but also for money. As developers become operators of applications, new fortunes will be made.

Take for example SalesForce.com. It provides a CRM service for its customers but rather than a big upfront price tag, users are charged by the month. The software itself is free. The way software is sold today is akin to the way factories produced electricity in the days before there were electric utilities. Factories had their own electric generators such as a water wheel. These days of course, factories don't generate their own electricity; they buy what they need from the electric company.

From a business point of view, applications will soon become a utility just like electricity. They'll be offered on a pay-as-you-go basis, with RiA basically installed on demand, and disposable like a box of tissues.

Hello World

So since I found Flex too slow, let's do a hello world using Java Desktop (JDNC), notice I used JXFrame (Java Desktop), not JFrame (Swing):

  JXFrame frame = new JXFrame("RIA");
  JPanel tabCms = new JPanel(new BorderLayout());
  JButton butCms = new JButton("Populate CMS");
  _gridCms = new JNTable();
  tabCms.add(_gridCms);
  tabCms.add(butCms, BorderLayout.NORTH);
  JTabbedPane tab = new JTabbedPane();
  tab.add("Cms", tabCms);
  frame.getContentPane().add(tab);

  //events
  butCms.addActionListener(this); //onClick

  display(frame); // standard pack and show
 }

 public void actionPerformed(ActionEvent arg0) { //onClickExec
  DefaultTableModel model = new DefaultTableModel(10, 6);
   _gridCms.setHasColumnControl(true);
  _gridCms.setModel(model);

 }

Your Table could be more complex. You could for example use Google's API to show something more interesting. Take a look at the JavaDoc for JavaDesktop to do more.

This can run in an IDE for testing. For real development you can use www.caucho.com/burlap (by Ferguson) to send messages or even SOAP (warped Doc/Lit for cross platform middleware). And you can use JGoodies (by Lentzsch ) for more advanced use. I found Spring is getting a bit more complicated and could be simplified. For example, it's more effective to use collections, the writing of getters and setters in lots of cases and be more loosely coupled.
For people that are learning Java, they can use something like this:
www.computersinmotion.com/cgi-bin/homeframeload.pl?formname=products

To deploy it on the server ... well there is a client piece we have to build, and a WAR, and I do it using Ant like this:

<project name="hello" default="war" basedir="..">

<target name="war" depends="helloria" >
 <path id="classpath">
 <pathelement location="hellosoa/misc/servlet-api.jar"/>
 <pathelement location="hellosoa/web/WEB-INF/lib/commons-beanutils.jar"/>
 <pathelement location="hellosoa/web/WEB-INF/lib/commons-chain.jar"/>
 <pathelement location="hellosoa/web/WEB-INF/lib/commons-collections.jar"/>
 <pathelement location="hellosoa/web/WEB-INF/lib/commons-digester.jar"/>
 <pathelement location="hellosoa/web/WEB-INF/lib/commons-logging.jar"/>
 <pathelement location="hellosoa/web/WEB-INF/lib/log4j.jar"/>

 </path>
   <javac srcdir= "hellosoa/src"
       destdir="hellosoa/web/WEB-INF/classes"
   />
 <war destfile = "helloria.war"
          basedir="hellosoa/web"
     webxml="hellosoa/web/WEB-INF/web.xml"
    />
 </target>

  <target name="helloria">
  <path id="classpath">
    <pathelement location="hellosoa/web/ria/jdnc.jar"/>
    <pathelement location="hellosoa/web/ria/jgoodies_forms.jar"/>
   </path>
   <javac srcdir= "helloria/src"
       destdir="helloria/classes"
   />
 <jar destfile = "hellosoa/web/ria/riarun.jar"
          basedir="helloria/classes"
    />
  </target>
</project>

The task above makes a JAR, and puts the client JAR in the WAR. For real development, I run commons-chains (by McClanahan; instead of IoC) on the server to send out DAO responses and go through a management layer.

Intranet users

A user would just surf to the WAR, and this index.jsp would “fire”:

<%@ page contentType="application/x-java-jnlp-file" %>
<%
   StringBuffer codebaseBuffer = new StringBuffer();
   codebaseBuffer.append("");
   codebaseBuffer.append(request.getServerName());
   codebaseBuffer.append(':');
   codebaseBuffer.append(request.getServerPort());
   codebaseBuffer.append(request.getContextPath());
%>
<?xml version="1.0" encoding="UTF-8"?>
<jnlp codebase="<%=codebaseBuffer.toString()%>" class="index.jsp">
  <information>
    <title>RiA-SoA</title>
 <vendor>Vic</vendor>
  <icon class="ria/splash.jpg"/>
 <icon kind="splash" class="ria/splash.jpg" />
  </information>
  <resources>
    <j2se version ="1.4.2+" />
    <jar class="ria/riarun.jar"/>
 <jar class="ria/jdnc.jar"/>
 <jar class="ria/jgoodies_forms.jar"/>
   <property name="srvc" value="<%=codebaseBuffer.toString()+"/soasrv"%>" />
  </resources>
  <application-desc main-class="com.bp.ria.Start"/>
</jnlp>

The reason I say Internet users is that while the “new” Sun has open source the Java Desktop, the “old” Sun is keeping Network Launcher proprietary and buggy.

(Ex: sourceforge.net/mailarchive/forum.php?thread_id=5034226&forum_id=8428
or
forum.java.sun.com/thread.jsp?forum=38&thread=372291&start=15&range=15&hilite=false&q= )

Unfortunately, IBM is driving behind Sun, and not getting into the passing lane to fix the issues and give people an alternative. Sun may not have the resources anymore. Open source does not wait, and there are several Network Launchers. I use netx.jar for Network Launcher like this:

java -jar netx.jar -jnlp host/webappfolder

People that have distaste for open source should not use this on the extra net. You can read more on: www.vamphq.com/jwsfaq.html (by Bauer). The Sun Network Launcher does need to improve the requirements ( sandbox security is too restrictive)

Getting Started with the IDE

If you have a working environment that you are happy with, then you can just type in the code I showed. And if you don't... What I started doing is zipping up an environment and just unzipping a working one whenever I need it. The zipped folder includes everything I need, even the JDK.

You can download a working environment with the above source, but it is 300MB download from sf.net. Just go to

  1. sourceforge.net/project/showfiles.php?group_id=105547
  2. download and unzip to c:
  3. Unistall all the Java from your machine. In inst there is jdk1.5.exe, run and install in provided folders. Set up ANT_HOME and JAVA_HOME. Done! (FAQ: What if it does not work? A: It works for me.)
  4. You can now edit in Eclipse and hit localhost/manager/reload?path=/ to reload the classes, without re-starting Tomcat.

This way you can do RiA/SoA quickly. Why is it so big? It's everything I use to develop, including pgSQL, so I do not have to download or configure.

Conclusion

JSF made a lot of promises a year ago related to UI, and now those promises have all come true... but in the form of the Java Desktop. With RiA/SoA, we have a return to a Client/Server of sorts, but this time with better deployment and better management capabilities.

With modem use declining in favor of DSL and broadband, and monitors getting above 21” and more, people expect to have a “Cinematic” (by Laslo) experience and more of an MTV look and feel. No need to develop skills in portlets or Tapestry or other html areas, there is no ROI. Welcome RiA! No more cross browser and back button issues.

It does not make sense anymore to develop additional HTML legacy applications; HTML is done for.

The future will bring more declarative programing, such as Longhorn's XAML and the like: javadesktop.org/jdnc/0_5/docs/tutorial/index.html
(But some people will keep writing C code inside of C++, ie, you should start getting used to doing UI declaratively, just like in Struts we do validation declaratively, just more things are in XML). People interested in the operation of RiA/SoA applications can join an RiA/SoA forum community at basicPortal.com. Yes, it's a PHP forum. One of the goals of the site is to re-implement the entire site in the Java Desktop, replacing PHP. The other goal of the site is to find clients that want us to operate RiA/SoA applications for a monthly maintenance/admin fee. Development is free. (No, we don't do html) Send us a paper mock up and 1st month's check (ex: $100 per month per screen for 3 years, includes operation and free development). Qualified developers that want in can contact me. (Again, the example of iTunes is good, they too have free software, just to underline a possible new business model).

I plan to publish an advanced example based on a forum using the Java Desktop.

Thanks to the Java Desktop, Java has a fine opportunity to own the desktop, once the Network Launcher issues are tunned.

About the Author

Vic Cekvenich has been in software development and consulting for almost 20 years. He wrote the 1st book on Struts a year before anyone else and his new book is coming out in 3 languages: www.amazon.de/exec/obidos/ASIN/3898642844/qid%3D1092073443/028-2613131-5504542

Edited by B. Dunklau

Related Topics: Spring framework, Client framework, VIEW ALL TOPICS
  • Digg This
  • Stumble
  • Delicious

Related Content

  • Spring framework
    • JSF best practices for optimizing mobile application performance
    • JavaOne 2014 speaker previews NetBeans and JavaScript
    • Advanced JSF Tutorial: The single page interface (SPI) with Facelets, Ajax and HTML5
    • JSF Tutorial: Completing the Ajax based Facelets application
    • Integrating Ajax into your Facelets pages: Death to JSF's request-response cycle
    • Template based web design with JSF Facelets: ui:insert versus ui:include
    • Creating pages based on a JSF template: Using the Facelets ui:define tag
    • Turning a web page into a JSF 2.0 template with Facelets
    • An introduction to template building with Facelets, CSS, HTML and JSF 2.2
  • Client framework
    • AngularJS: A JavaScript framework built with software testing in mind
    • From the mobile browser to the cloud: The expanding role of JavaScript
    • Step-by-step guide to Android developme
gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.