Activate your free membership today | Log-in

Friday, August 29th, 2008

GWT 1.5 final release is shipped and out the door

Category: GWT, Google, Java, Library

I have seen the GWT team working very hard indeed on GWT 1.5, and they must be very happy to see the final release shipped and complete:

GWT 1.5 delivers what we think are an impressive number of improvements, about four hundred issues if you’re counting. We’re also happy that one of those is issue 168, our most-requested feature, Support for Java 5.

The high level new feature sets are:

  • Java 5 language support and enhanced JRE emulation
  • Performance optimizations and easier JavaScript interop
  • Prettier widgets, better DOM, accessibility, and bi-di

You can see a lot of this at work in the showcase area. There you will see all of the widgets and examples that come out of the box, and the community has developed even more for you. In particular, Ray Cromwell has some great real world examples that he shares in his book and talk.

Download GWT and take a look.

Posted by Dion Almaer at 10:51 am
1 Comment

++++-
4 rating from 24 votes

Monday, August 25th, 2008

Putting together GWT and Spring

Category: Java

Dave Kuhn has put together a comprehensive guide to piecing together GWT and Spring, a nice recipe for the Java heads among you.

Dave starts out by detailing why you would want to do this, and how it changes the architecture of your application.

He then gets to a tutorial that has you creating the project correctly, and configuring an actual service. Once you are done with the code, you need to setup hosted mode to point to a nice external tom cat via:

-out www GwtWisdom/GwtWisdom.html
-noserver
-port 8080

Posted by Dion Almaer at 7:51 am
1 Comment

++++-
4.1 rating from 20 votes

Wednesday, July 2nd, 2008

Loom: Annotation based Java framework

Category: Framework, Java

Ignacio Coloma has announced Loom 1.0 RC 1. Loom is an annotation-based java web framework that includes a ton of new features in this release. After some selective process, these are the bits that could be of most interest for Ajax developers:

  • Generates HTML 5 markup (with data-* fields), including CSS classes
    with the property type.
  • Based on prototype
  • An ever-growing list of (progressive-enhancement) web components,
    including: multiple file upload, tabs, menus...
  • Dead-simple javascript validation library with i18n support.
  • ...which mimics the process at the server, in case javascript is disabled.

Just give it a try at the demo. Try introducing invalid input, and check the sources by clicking the "View source" link at the top right of the page. Everything in the demo should work with javascript disabled, including multiple file upload.

The framework also includes a libraries repository which pulls debug/optimized javascript from the google CDN:

HTML:
  1.  
  2. <l :script resource="prototype"/>
  3. <l :script resource="scriptaculous">
  4.  <l :param name="load" value="builder,effects"/>
  5. </l>
  6.  

This snippet of code would translate into this, if development is disabled:

HTML:
  1.  
  2. <script type="text/javascript"
  3. src="//ajax.googleapis.com/ajax/libs/prototype/1.6.0.2/prototype.js">
  4. </script>
  5. <script type="text/javascript"
  6. src="//ajax.googleapis.com/ajax/libs/scriptaculous/1.8.1/scriptaculous.js?load=builder,effects">
  7. </script>
  8.  

Or this if not:

HTML:
  1.  
  2. <script src="/js/prototype-1.6.0/prototype-1.6.0.2-shrinkvars.js"
  3. type="text/javascript"></script>
  4. <script type="text/javascript"
  5. src="//ajax.googleapis.com/ajax/libs/scriptaculous/1.8.1/scriptaculous.js?load=builder,effects">
  6. </script>
  7.  

More details about the framework are at the reference guide. Ignacio would be grateful for any feedback!

Posted by Dion Almaer at 10:28 am
1 Comment

+++--
3.9 rating from 14 votes

Friday, June 13th, 2008

Pivot: Swing++ as New Java-based RIA Platform?

Category: Java, UI

And now for something a little bit different on a Friday. Greg Brown from VMWare pointed us to the fruition of nearly a year's worth of R&D: Pivot, a new GUI toolkit for Java.

While traditionally Java Applets and the Web have mixed together about as well as concrete and peanut butter, the upcoming revised Java plug-in might give a window for Java-based GUI toolkits to be of interest to Web folks.

While Pivot's source code is still forthcoming, a quick glance at its classes shows an architecture with a strong resemblance to Java's built-in Swing GUI toolkit, but with many of Swing's rough edges smoothed out. As a long-time Swing developer, I'd characterize it as attempt to create Swing++.

Similarities to Swing include a light-weight rendering model (i.e., it doesn't wrap native components), a nearly identical component contract, a very similar system of UI delegates, and a very similar event model. Differences include a cleaner API (by virtue of nixing direct interoperability with Java's ancient AWT toolkit), different approach to layout, fresh implementations of common GUI components, and a new collections framework (inspired by Java's collections framework but... different).

Thinlet is another, older alternate GUI toolkit for Java that draws its own components and targets Applet developers (though a new version is under development).

Posted by Ben Galbraith at 7:05 am
9 Comments

+++--
3.8 rating from 28 votes

Tuesday, June 3rd, 2008

crossdomain.xml, Java, and JNLP

Category: Java

Joshua Marinacci has detailed how Java SE 6 update 10 supports the same crossdomain.xml that Flash supports, and how you can marry it with JNLP to allow you to do Applet mashups without permission dialogs.

The applet security model, known as the sandbox, only lets applets connect to the webserver they were loaded from. They cannot connect to anywhere else unless they are signed. Signing is great when you need access to more than what is allowed inside the sandbox, but it has two problems: the user will receive an ugly warning dialog about the applet, and the applet will have full access to the user's computer. Full access is overkill when all you want to do is talk to a webservice on another server. Surely there is some middle ground between the sandbox and full access? Well now there is.

The key is supplying a backwards compatible way of tying to the new JNLP version:

HTML:
  1.  
  2.     <applet code="photostrip.Applet"
  3.             archive="http://projects.joshy.org/demos/PhotoStrip/webstart/PhotoStrip.jar"
  4.             width="400" height="200"
  5.            >
  6.         <param name="jnlp_href" value="http://projects.joshy.org/demos/PhotoStrip/photostrip.jnlp">
  7.         <param name="flickruser" value="31706743@N00"/>
  8.         <param name="size" value="100"/>
  9.         <param name="cols" value="4"/>
  10.         <param name="rows" value="2"/>
  11.     </param></applet>
  12.  

Now the JNLP file points to the the unsigned jar:

XML:
  1.  
  2. <jnlp spec="1.0+" codebase="" href="">
  3.     <information>
  4.         <title>PhotoStrip</title>
  5.         <vendor>Joshua Marinacci</vendor>
  6.         <offline -allowed />
  7.     </information>
  8.     <resources>
  9.         <j2se version="1.5+" href="http://java.sun.com/products/autodl/j2se" />
  10.         <jar href="unsigned/PhotoStrip.jar" main="true" />
  11.         <!-- Application Resources -->
  12.     </resources>
  13.   <applet -desc
  14.       name="PhotoStrip"
  15.       main-class="photostrip.Applet"
  16.       width="400"
  17.       height="200">
  18.   </applet>
  19. </jnlp>
  20.  

Note: you should be aware of security issues with open cross domain files.

Posted by Dion Almaer at 8:19 am
2 Comments

++---
2.6 rating from 8 votes

Tuesday, May 27th, 2008

SoundManager 2 Updates: Speed and Demos

Category: Java, Sound

SoundManager 2 update

Scott Schiller has updated one of our favourite libraries, SoundManager. Being able to simply play some audio from your Ajax applications can be great, as long as you don't use it gratuitously.... although we tend to do that a little in some of our demos :) We used SoundManager in our Wii Darts application.

The new version has performance improvements so the sound happens a lot quicker, a few bugs are killed, but most of all you will see some really great demos to cover use cases from users such as "I just want to be able to click and play a MP3 link in-page."

Some of the cool new demos:

Download the latest library.

Oh, and you gotta love the Web 2.0 and Web 3.0 explanations of SoundManager ;)

Posted by Dion Almaer at 7:39 am
Comment here

++++-
4.3 rating from 19 votes

Friday, May 16th, 2008

Spring WebFlow 2.0; JavaScript Module Released

Category: Dojo, Java, JavaScript, Library

Spring Web Flow 2.0 has been released which includes a new Spring JavaScript module.

Here is an example of an onclick wrapper calling an Ajax event:

HTML:
  1.  
  2. <a id="prevResultsLink" href="search?searchString=${searchCriteria.searchString}&page=${searchCriteria.page - 1}">Previous Results</a>
  3. <script type="text/javascript">
  4.     Spring.addDecoration(new Spring.AjaxEventDecoration({
  5.         elementId: "prevResultsLink",
  6.         event: "onclick",
  7.         params: { fragments: "body" }
  8.     }));
  9. </script>
  10.  

I got to sit down with Keith Donald and Jeremy Grelle from SpringSource and talk to them about the going-ons on the Web tier. There are a couple of moving parts, from the core Web framework (Spring MVC), to the Spring Webflow controller engine, to the new Spring JS module.

Spring JS abstracts on top of other JavaScript libraries (this release supports Dojo, but more can come), and aims to make certain tasks very easy to do. Jeremy talks about some of the use cases, such as form validation. The library could be used stand alone, but of course there is nice integration with the server side Spring frameworks too. This allows you to annotate in Java, and get nice Ajax behaviour on the client.

Posted by Dion Almaer at 12:01 am
2 Comments

+++--
3.9 rating from 60 votes

Wednesday, May 7th, 2008

Wii Darts: Powering Ajax applications with Wii controllers

Category: Games, Java, Presentation, Showcase

Ben and I gave a presentation at JavaOne on what's new with Ajax. Since this was JavaOne, we skewed a little more than we normally would to Java topics, and one of them was using the new Java Plugin, that has great new features such as being able to take a running applet out of the web page, and having it continue to live after shutting down the browser. Java is running out of process here, which also helps the "Java crashing the entire browser" problem.

Anyway, back to our demo. For some context, last year at JavaOne had us performing Guitar Hero on stage, so we knew that we had to use a gaming console in some way. This year it had to be the Wii, but instead of using the console, we decided to just use the controllers.

Wouldn't it be cool to control a Web page using the controllers? We thought so, and we set to it. You can talk to the Wiimotes via Bluetooth, so we needed a stack that would allow us to do just that. Java has a bluetooth stack. We could get an applet to talk to the Java stack. Hmm.

It actually took quite some time to test out the various stacks out there. In the end we went with a native system called Wiiuse that a lot of Wii hackers use. There is a wrapper library called Wiiusej that gave us exactly what we needed.

A quick test later and we had an application that was talking between the remote and the program. It turns out that the main controller sees a series of IR lights that are in the Wii sensor bar, and this allows you to simulate the system with any decent IR source. In the presentation room the big lights that shine on stage were strong enough to act as a sensor bar so we won't even have to use it. We can just point out to the crowd.

Anyway, back to the application. We then wrote a Java class that acts as a state machine for what the remote is doing. It understands the movements, which buttons are pushed, how fast you are moving the device. With this data we could build a simple darts game. With the state machine Java code, and an Applet wrapper that exposed the information, we were ready to get to the Ajax side of the house.

We painted a darts board onto the screen and then had JavaScript start polling the Applet for information via JSObject (As simple as: document.nameofapplet.pollmethod()). This turned out to be more stable than talking the other way, even though it meant we were polling instead of being entirely event driven. When the JavaScript code polled the applet it would pass back a data structure with the data for the coordinates of the remote, and whether the dart had been fired (button A to fire, button B to reload). We would move the dart image on the screen as you move the remote, and when fired we kicked off an animation to fire the dart at the board.

At first, it was all too simple. You setup the shot and it would get the right area every time. Not a fun game. We then decided to add some simple physics to the Ajax game. We took into account the velocity of the throw (if weak it would fall down) and how straight your shot was. If you wiggle around, the dart will not be accurate.

Anyway, this was a lot of fun, and shows that as much as we mock Java applets, if we forget about using them as fancy blink tags, and instead think of them as more extension points, maybe there is life for them.

The video below shows you a demo of the application, the source code with an explanation, and more details.

Posted by Dion Almaer at 6:08 pm
7 Comments

++++-
4.6 rating from 31 votes

Monday, April 28th, 2008

Java in JavaScript

Category: Games, Java, JavaScript

As John Resig reports, the Japanese Shibuja.JS user group managed to port (at least in parts) the Java Virtual Machine over to JavaScript. The project is called Orto and there is a Japanese PDF explaining the details (I guess) available on John's site.

Using this you can convert Java code into bytecode and embed it in the document.

JAVASCRIPT:
  1.  
  2. "java/lang/Thread 1316742099":function(){var orto333=orto245[0];
  3. var orto336=orto350(orto333);
  4. if(orto336.orto340!=orto310){orto223("java/lang/IllegalThreadStateException",null);
  5. return ;
  6. }
  7.  

One of the examples shown is a pretty cool Tetris game:

Screenshot of Xetris - a Java Tetris in JavaScript

As Orto simulates the multithreaded nature of Java with yields and timeouts this is of course hard-core simulation (read: hack), but the benefit are that you could Java Games on non-JS devices, like the iPhone.

Orto also seems to try to simulate the Java UI conventions, thus making it easy to convert existing applications (to a certain degree as there is no equivalent in HTML for the richness of Java UIs unless you build them yourself as libraries ike Dojo or Quoxdoo did).

More details are available on John Resig's Blog

Posted by Chris Heilmann at 1:26 am
6 Comments

+++--
3.8 rating from 14 votes

Friday, April 11th, 2008

Java Plugin: The Kernel is back

Category: Java

Ethan Nicholas of Sun has posted an article on Java 6 update 10 which just came out in beta to play.

For Java folk there are some huge wins, and for the first time in ages the Java applet has huge changes. If Java Applets can get past the sniggering baggage, there is actually interesting things to see there.

What was the pain again?

Once a Java program is up and running, it's generally smooth sailing.
Modern Java Runtime Environments (JREs) are stable, reliable, and fast.

Unfortunately, getting to the "up and running" part has historically been
more difficult than it should be. Challenges have included:

  • Difficult to detect JREs, especially from a web browser
  • Difficult to automatically install new JREs
  • Large download size
  • Poor cold start performance
  • Little overlap between applets and Web Start programs

Java 6u10 was created as a response to these challenges. By carefully
avoiding public API changes, we can get the fixes into your hands sooner --
no need to wait for Java 7!

And the solutions?

Java Kernel

Java Kernel is a new distribution aimed at getting Java software up and running faster. Instead of a full JRE, users download a small installer (the "kernel") which includes the most commonly needed JRE components. Additional components are downloaded as needed, and the JRE will download remaining components in the background and then reassemble itself.

In the current build, the typical download size for Swing programs and Java applets is on the order of 4-5MB, compared to 14.4MB for the full JRE.

Next-Generation Java Plug-In

Java 6u10 includes a brand-new implementation of the Java Plug-in, which is
used by default as long as you are using Firefox 3 or Internet Explorer. The
next-generation plug-in runs applets outside of the browser in one or more
separate processes. Applets still appear inside of the web browser window as
they always have, but this means that it is now possible to use different JRE
versions, command-line arguments, and configurations to run different applets.
The isolation provided by running the web browser and the JRE -- two very large,
very complex pieces of software -- in separate process spaces improves the
reliability of both, and gives applets the same flexibility and control over JRE
configurations that other Java software has always enjoyed.

Since applets now feature the same powerful JRE selection and configuration
that Java Web Start programs do, it was only natural to use the same mechanism
for both. The Java Plug-In now supports using Java
Network Launching Protocol
(JNLP) files to specify applet configuration and
startup options. With very little additional work, you can now deploy the same
program as both an applet and a Web Start program, and still take advantage of
JNLP services such as PersistanceService and

FileSaveService.

New Plug-In Advantages:

  • Improved reliability
  • Improved JavaScript communication
  • Per-applet control of JRE command-line arguments
  • Per-applet control of JRE memory settings, larger maximum heaps
  • JNLP support
  • Per-applet JRE version selection
  • Improved Vista support

Much more information about the new plug-in can be found in the release notes.

Java Deployment Toolkit

The Java Deployment Toolkit makes deploying Java applets or Java Web Start
programs a snap. The
Deployment
Toolkit JavaScript file
provides:

  • Accurate detection of installed JREs
  • Seamless JRE installation
  • Complete applet launching (JRE detection and, if necessary, upgrading)
    in a single line of code
  • Complete Web Start program launching in a single line of code

The following HTML code is all it takes to ensure that Java 1.6 is installed and
then a Java applet is launched:

JAVASCRIPT:
  1.  
  2. <script src="http://java.com/js/deployJava.js"></script>
  3.    
  4. <script>
  5.   deployJava.runApplet({codebase:"http://www.example.com/applets/",
  6.      archive:"ExampleApplet.jar", code:"Main.class",
  7.      width:"320", Height:"400"}, null, "1.6");
  8. </script>
  9.  

Also note, that with this version you can take a running Applet in the browser, pull it OUT of the page, close the browser, and see the applet still running (since it runs in a different process). This is very cool indeed.

Add to all of this the easy bridge between Java and JavaScript, and there are interesting opportunities.

Posted by Dion Almaer at 12:32 pm
16 Comments

++++-
4.5 rating from 33 votes

Tuesday, April 1st, 2008

GChart 2.0: Give me some pie

Category: GWT, Java, Library

GChart 2.0

Version 2.0 of GChart has been released:

The main idea behind GChart is simple: You can make very nice charts efficiently out of a reasonably small number of 1-cell Grids (for the aligned labels) and (empty) Images (for everything else), styled and positioned appropriately on an AbsolutePanel. Not surprisingly, bar charts don't suffer at all under the limitations imposed by this strategy--but (as long as you don't mind using dotted connecting lines or banded-filled pie slices) line and pie charts also do remarkably well.

With version 2.0 the library adds support for pie, line, and area charts, baseline-based bar charts, and more.

John Gunther wrote up some of the technical details:

Squaring the Pie Slice

Some of you may recall the original GChart 1.1 post/discussion:

Reading this, you may wonder how I ended up implementing pie slices
and arbitrary angled connecting lines. Did I use the "transparent
border triangle trick" and/or clever algorithms from walterzorn.com?

Though I tried to use these, I reverted to something a lot simpler:
dotted connecting lines and banded-filled pie slices. Two new Symbol
class properties, fillSpacing and fillThickness, let you control the
spacing of the dots/bands and their size/thickness.

Though this approach means you may sometimes have to choose between
visual chart quality and speed, these new properties make it easy for
you to control this tradeoff. Besides, I like to think that dotted
connecting lines and banded fill pie slices really don't look all that
much worse than the solid fill variety. But then again, I could never
understand why no one ever used square pie charts...

In any case, the whole point of GChart is to layer the chart on top of
standard GWT Widgets, so, since those Widgets can only really draw
rectangles efficiently, I decided to make a virtue of necessity and
whole-heartedly embrace this dotted/banded look.

CSS Convenience Methods: A cure for "CSS anxiety disorder"?

For many months I suffered from "CSS anxiety disorder": a condition
arising from one's desire to use CSS to specify an attribute (and thus
conform to a GWT best practice) while simultaneously wanting the same
property in the Java API (so that it would not be unnaturally
segregated from closely related features).

To address this (possibly imaginary) problem, the GChart 2.0 Java API
includes "CSS convenience methods" that can (optionally) override
traditionally CSS-based attribute specifications for certain selected
CSS attributes.

To some, this may seem like a fine point, since you could easily do
the same thing via a GWT DOM class method call, but to me, once you
invoke a DOM method you are thinking of the GChart as an HTML element,
and for some usage scenarios, that just isn't logical.

For example, for some applications, the background color of a GChart
is mainly about how the color-scheme of the chart blends in with the
surrounding page, and for these applications a CSS-based specification
makes good sense. Yet, for other applications, it is mainly all about
how well background color matches with, say, with the pie slice
shading pattern. That is, in some cases, background color is better
viewed as a feature of the GChart considered as a Java object
independent of its connection to any web page. So why can't you just
call GChart.setBackgroundColor in such cases? With GChart, you can.

To assure that the two specification methods can exist harmoniously
together, GChart recognizes a special property value, GChart.USE_CSS,
which instructs GChart to stand aside and allow the traditional CSS
cascade to define the attribute. For all such "dual access" GChart
Java properties (which are simultaneously also CSS attributes),
USE_CSS is the default property value. This assures that you can use
CSS just as you would with a standard GWT Widget whenever it makes
more sense to control that attribute from the "GChart as HTML element"
perspective.

Thanks to these CSS convenience methods, I have attained inner peace
through Java/CSS redundancy. I recommend the same treatment for anyone
else suffering from "CSS anxiety disorder". See the GChart.USE_CSS
javadoc comment for more information.

I am sure that John will be porting this to the GWT for JavaScript 2 at some point soon!

Posted by Dion Almaer at 8:06 am
1 Comment

+++--
3.8 rating from 11 votes

Wednesday, March 19th, 2008

Echo 3 releases client side component model

Category: Framework, Java, JavaScript

Echo has been known as a Java server side component framework, but with the release of Echo 3, they have added a way to build component applications using JavaScript:

Client-side Echo applications do not require an application server, and can also be run entirely offline.

With Echo3, the formerly server-side-only component framework has been recreated in client-side JavaScript. This was not a direct “port”, but rather a re-imagining of the framework with the ideals of JavaScript development in mind. For example, the client-side version of the framework takes advantage of JavaScript's object and array literal syntaxes to create a capability called "hierarchal component construction", where an entire hierarchy of components can be created in a single call. Such code winds up being extremely readable, as, when naturally indented, it resembles the component tree.

Core.js framework

A low-level framework, called “Core.js” was created to ease development of object-oriented and event-driven code in JavaScript. Core.js provides an inheritance model for building JavaScript objects using class-based (rather than prototype-based) inheritance. It additionally offers the capability to specify abstract classes and methods, and features “pseudo-private variables” where a class can reserve internal method/field names that cannot be overridden by subclasses. The framework includes utilities for managing events and listeners, and can register event
handlers on object instances.

New Back-End / Rendering APIs

The “back-end,” which is responsible for rendering components within the web browser, has been re-engineered for Echo3. Instead of e