Thursday, May 31, 2007

Easy gmail "API" decode

Not so long ago I complained about there being no official gmail API. I got some good comments about either using gmailthis bookmarklet or sending through the gmail smtp server.

What I ended up doing was very simple.

I noticed that google toolbar has an option in its settings where I can check "Send with gmail", which makes gmail open up in a new mail when a mailto: link is clicked. All I had to do was to produce some examples of the kind of new emails I would like to be able to open up in gmail, and then look at the link that google toolbar produces with this option on. An easy way to "reverse engineer".

Wednesday, May 30, 2007

ActiveRecord and HAVING clauses

I found myself working on a rails project a bit and for the first time had the need for a HAVING clause in a query. Hmm, that was not mentioned in the docs. Could it be missing from ActiveRecord. Yep! And not.

Found this good discussion on the subject, where Blake Watters suggests adding support for ":having" on find to the core of ActiveRecord. I agree on this being a needed feature, but there is also a mention of a work-around, that I am using now. Simply put your HAVING clause last in the ":group" key. Like this:
@upcoming_courses = Course.find(
:include => 'course_registrations',
:conditions => [ "show_online = :show AND begins_on > :now",
{:show => true, :now =>} ],
:order => 'begins_on asc',
:group => ' HAVING count(*) < limit =""> 3
And it works...

Keyboard Focus problem with IDEA/Swing and KDE/X

I have been having trouble with loosing keyboard focus in IDEA when doing stuff like Ctrl-E or Alt-Enter for quick-fixes. If you are having such problems, try doing this:

export AWT_TOOLKIT=XToolkit

It helped on a SuSE box running IDEA 6 and 7 on KDE.

I think the problem is more with Swing combined with X/KDE than with IDEA. When setting AWT_TOOLKIT to XToolkit, you are choosing a new implementation of AWT against the native UI components of the platform.

Monday, May 28, 2007

Flash for Java Programmers: Lesson 2 - Using UI Components

Steps on learning to develop Flash, with a Java developer focus...

This is lesson 2 in my series of posts on what I learn about developing filthy rich flash apps using flex2. The first lesson can be found in a previous post, where I showed how to setup a maven build using flex2 command-line compilers.

In this post, I will show off some of the build-in UI components that you get, simply by using flex2.

Containers and Controls
There are two kinds of UI components in flex: Containers and controls. This is not much different from other UI toolkits.

Containers define an area in which other containers and controls can be layed out. As such, the containers define hierarchical structure.

Controls are stuff like buttons, input fields, checkboxes, ...

A simple example
Just to show a little bit (and it really is a little bit compared to what is in the UI component library), I will give a small example. There should be a flash just below here:

And below is the mxml source, which produces the above UI:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="">
<mx:Fade id="fader"/>
<mx:TabNavigator borderStyle="solid" width="100%" height="100%">
<mx:VBox label="Tab 1" showEffect="fader">
<mx:TextInput id="data" text="Enter data here"/>
<mx:Button label="Click me" click="'You entered: ' + data.text)"/>
<mx:VBox label="Tab 2" showEffect="fader">
<mx:RichTextEditor />
As you can see, we have a tabbed pane with two tabs. A TabNavigator components is a tabbed pane, where each pane is simply a VBox with anything in it. Entering text and clicking the button on tab 1 opens an alert with information about what you entered. On tab 2, there is a full Rich Text Editor component. Notice how there is a nice fading effect when shifting tab.

Now, this is all very nice in itself, but I would like to emphasize a couple of points here:
  • The fading effect is simple defined and applied. No special coding needed.
  • When the Alert pops up, all the below UI is grayed out and made inaccessible--flex is implementing the alert popup as a modal dialog. No special coding needed.
  • The Rich Text Editor talks for itself. We know how hard this is to get right in HTML/JS on many browsers and OS.
Static vs. Dynamic UI construction
In this lesson we were using mxml to statically define the UI components in the application. You can also use ActionScript to dynamically construct and layout your UI. This is done by instantiating instances of the classes behind the mx:xxx tags and adding them into the UI tree. A later post might look at this.

Downloading the source
I have zipped up the sources. It can be downloaded from here. Ready to be build with maven.

Friday, May 25, 2007

Why is there no official GMail API?

I have a client who wants to integrate his web application with gmail. In effect, I simply need to open up a new mail in gmail initiated from an action in our web application. The email needs to have to/cc and subject prefilled and that is it. No more.

But, I cannot find an official API to gmail on and why is that? There has to be a huge market for this usage. And google seems to have apis for some of their other products.

Of course, there are projects like g4j, but I took a look at the implementation, and it seems rather fragile to me. The author has reverse engineered the protocol, as in the code is calling URLs with parameters as API against gmail. Good work I am sure, but it can easily break when google releases new versions.

Am I missing something here? ...

Tuesday, May 22, 2007

Flash for Java Programmers: Lesson 1

Steps on learning to develop Flash, with a Java developer focus...

If you have seen my latest posts, you will know that my current project is going to use Flash. You will also know, that I am only starting to learn "doing it the flash way". I am used to developing user interfaces with HTML/JavaScript and using an all server-side technology stack with spring/hibernate combined with web frameworks like Tapestry and Struts.

I thought I might share my knowledge with you all, as I go along and learn stuff. After all, you all might have some useful input to me, on how to do things in flash in a better way. I would hope so.

So here it goes, ...

Lesson 1: Setting up a build

I will be using the free Flex2 environment from Adobe when developing. Adobe also has a development tool/IDE but I will not be using that. Why? Because it is Windows bound, because I like to be IDE independent and because I simply like to build on the command-line. It should build as easily on Mac and Linux as on Windows!

That said, my setup is Windows XP with Maven 2 for building.

1. Download some software
Of course, you need Java (duh!). I will be running JSE5.

You need maven too. Download from here and follow its installation instructions. There are good guides on this, and I will not go into details here.

Then, download the Flex2 SDK from Adobe. Unzip the downloaded file into a place where you want it to be. I will reference this unzipped place as FLEX2_SDK_HOME from here on.

2. Create the POM
Create a new directory, say "lesson1", and create a pom.xml file for maven which looks like this:

<project xmlns="" xmlns:xsi=""
<!-- the swf/flex2 plugin -->

You need to set the "flex.home" property to where you placed FLEX2_SDK_HOME when unzipping the SDK. If you know maven, you also know that you can take this property out and put it into your global settings.xml instead, if you like.

In the "build" element I setup the maven-flex2-plugin from Israfil. It needs to know the SDK home and can then execute the compiler on the flex sources we are going to write. This plugin knows the "swf" packaging, which is the flash file format that the flex compiler outputs.

I also setup two repositories. One for the main maven repository and one for where the Flex2 plugin can be downloaded. And of course, these can also be moved into settings.xml, if you know maven well enough.

3. Create some flex2 source
Then, create the directories "src/main/flex". This is where the maven plugin which compiles Flex2 code expects to find its sources (relative to the pom.xml).

In "src/main/flex", create a file called "Main.mxml" with this content:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="">
<mx:Label text="Hello, Flash World"/>
4. Building
Okay, we are ready to compile. Standing in the directory where you put the pom.xml, you type "mvn" and hopefully, the plugin will be downloaded, the flex compiler executed against the Main.mxml and a ".swf" file should be produced in the target directory.

But, first compile will show an error like this:

[INFO] Loading configuration file C:\sandboxes\ria\flex2-lessons\flex2-sdk\frameworks\flex-config.xml
[INFO] defaults: Error: unable to open './winFonts.ser'

What you need to do is open the flex SDK configuation file from FLEX2_SDK_HOME/frameworks/flex-config.xml, search for "winFonts.ser" and ensure the "local-fonts-snapshot" element is not commented out.

Now, build again, and it should produce a "flash-lesson1-1.0.swf" file in the target dir.

If you have the standalone flash player installed (downloadable from Adobe), you can double-click the output file and see it run. If not, you can wrap it in a html file which opens in a browser. Create a file "index.html" in the target dir with this content between the body tags:
<object width="100%" height="100%">
<param name="movie" value="flash-lesson1-1.0.swf">
<embed src="flash-lesson1-1.0.swf" width="100%" height="100%" play="true">

The "object" tag is for IE and the "embed" tag is for Firefox.

Possible issues
You will need flash player 9, as this is what flex2 compiler output require! Flash player 7 and 8 does not work.

Downloading the source
I have zipped up the project as I describe how to build above. It can be downloaded from here. Ready to be build with maven.

Hope this helps someone. Soon, I will post a new lesson on some of the stuff I am learning.

Monday, May 21, 2007

IDEA and the Bindows RIA web framework

In Selena (the IntelliJ IDEA upcoming v7) JetBrains pushes news into our throats using their JetConnect plugin. A flashing little icon in the bottom told me, that there were fresh news. Well, it turned out to be an add for a RIA framework called Bindows and of course, a plugin for IDEA to help working with Bindows.

What caught my interest was the fact, that JetBrains are willing to call this the #1 best Ajax framework and push the news of the plugin out to the users. JetBrains makes a killer IDE and maybe Bindows is a killer too then? I set out to take a (short) look.

Firstly, I must say you are quickly up and running. Bindows is a HTML/JS based RIA framework, where you code all your UI in JavaScript or their XML format. Using the plugin in IDEA, I can easily launch my application (which is simply an xml file) in IE or Firefox. The plugin produces a html launch file, which basically executes some javascript to kickstart my RIA application.

There are all sorts of goodies like completion and stuff. Seems like a nice integration job done with the plugin. Bindows also seems nice. There is also some unit testing stuff, that I haven't had a look at yet.

The programming model seems to mirror that of flex, when you define UI in XML or JavaScript and provide logik in JavaScript/ActionScript. But Bindows does not require a runtime.

But, it is:
  • Unknown, at least to me
  • Closed and licensed for development and runtime
Would like to hear from anyone knowing Bindows...?

Decided on a RIA web framework: Flash!

Previously, I posted about having to decide on a RIA technology. I got some good feed-back on my post at that time, which helped guide our evaluation process. So what did we choose?

We ended up choosing Flash as technology and Flex2 as development tooling. The decision is not exactly final yet, but we have decided to go with this for now. That is, we start developing real business functionality in it, and of course will continue evaluation as we go. There is still the possibility that we bump into a show-stopping issue, which will make us go back and re-evaluate.

Here are some pros and cons on the technology, as we see it

  • Proven UI technology through many years
  • The runtime is everywhere--nearly no install needed, even though flex2 requires flash 9
  • Good documentation--as in, really good documentation, it seems
  • Large user community--at least for Flash as a technology in general
  • Easily integrated into our build--we are using the flex2 maven plugin by Israfil
  • Closed technology--Adobe is still sitting on the runtime
  • Hard to test--Still have not found a good way to automate test of the UI layer
To be honest, the choice is also based on gut feeling. Those of you who read my choosing RIA framework blog entry know that we were left with GWT, Flex/Flash or Swing/JWS. After looking at them and working a bit with them, our gut feeling told us to go with Flash.

Flash is like a compromise between extremes, where GWT and Swing/JWS are the extremes.

GWT requires no runtime except the browser. Totally lightweight. But it is also pushing the HTML/JS technology to its limits. For the UI functionality we are to make, it will be really hard to get working, also with GWT.

With Swing/JWS, there is no doubt we could do just about anything in the UI we would like to. But, it would also be a real burden on the client with runtime installation. If we could just wait for the consumer JRE, but we cannot.

But flash, on the other hand. It can do nice UIs in an easy to develop way (it seems) and its runtime will roll onto the client much easier.

So why did we not choose JavaFX? It is too bleading edge and has too heavy a runtime. It is just, so much not out there yet :-)

Issue with automatic testing
We hope to resolve the issue of automatic testing of the UI using some kind of robot technology. Something driving a mouse and clicking on the UI in an automated manner. Will have to look at this.

About evaluating frameworks
In my last post about this issue I got some really good comments. Some of them related to us not actually evaluating all the frameworks we were looking at. That is correct! It becomes more and more clear to me, why the choice of new web technology in Java land is hard. We have so much to choose from and it is only by actually using the technology to provide real business functionality, that you gain true insight into the web framework of choice.

This is also why we have now stopped further experiments with GWT and Swing/JWS and choosen to go with flash for now.

Wednesday, May 16, 2007

Slides: JRoR talk at danish Java User Group

Recently, I did a presentation of JRuby to a danish Java user group called JavaGruppen. The presentation was about JRuby the project, what it is and what it can do and of course, how nice it is to deploy Rails on it :-)

The slides can be downloaded here.

Friday, May 11, 2007

Overriding JPA mappings with Hibernate specific ones - can it be done?

Before JPA, I have always preferred Hibernate for O/R mapping, but for a project we are starting up right now, we are planning to use the standard JPA annotations. Why? Because they are a standard, and they look pretty much like what Hibernate can give us.

But then I read this post from JavaOne about what might be coming in JPA 2.0, and it gave me a feeling of quite some bit of functionality present in Hibernate but missing in JPA 1.0. A short list of what might be coming in JPA 2.0 and hence missing from the current JPA:
  • @Embeddable to map columns of a table to a class inside another class without having to map the embedded class to a table by itself
  • Ordered lists in the database
  • Specifying access types (field or property) on a pr. entity class level instead of on all entity classes
  • Uni-directional mapping on 1-N relations
There are others mentioned in the post, but these stand out to me as things that (a) I have used myself and found to be usefull, and (b) something that hibernate already has.

So, here is the question: "Is it possible to use JPA standard annotations for mapping the entities and then falling back on Hibernate specific mapping annotations when I need a specific feature that JPA does not have?". Of course, for this to work, I must be using hibernate as the JPA provider implementation.

Thursday, May 03, 2007

Choosing a RIA web framework is seriously hard :-(

So, as I have previously said, choosing view technology is a hard job :-)

A couple of days ago, at a client, we were sitting down to choose a new web framework for doing some upcoming Rich Internet Applications (RIA). We listed the contenders and tried to score them against each other on what we found most important. The table below shows the contenders and the score we gave them (1-to-5, 1 is worst, 5 is best). The ones I have made strike-through on failed our conditions:
NameUnit testableFunctional testableQuick devel/build cycleFun factorRIA easinessPlatform independent
Tapestry 5525411
Flex2 (flash)??5455
Open Laszlo (flash)125255
Swing with JWS5?5455
All the DHTML-based ones score about the same on "functional testable" as they all rely on the same kind of tools (watir, selenium, jwebunit, ...) for doing the testing. And they score low, because previous experience have shown us, that this is hard when you get wild with the RIA functionality.

The proprietary runtime ones on the other hand, are even harder. How do you assert if something shows correctly in a flash application after clicking button x? Seems like Adobe/Mercury has something going for flash, but it is closed source/buyware and windows-only.

Quick development/build cycle
We are real tired of having to build and deploy and restart container to be able to see the changes we have made. It takes too long. This is important!

Fun factor
Do not tell your boss about this one, even though it is important too :-) We need to work with this in a long time after deciding on it. It needs to be fun too. I would simply hate writing JSPs to JSF and most probably think about quitting.

Platform independent
By this we mean: "Does the same code look and behave the same in most browsers on most platforms?". It needs to. No other than GWT from the DTHML-based ones score high on this. We feel that google has put a lot of effort in actually testing their components on many platforms. Flash and JVM-based ones score high here.

The ones who did not make it
Here are some short notes on the ones we deemed out and why:
  • As a previously big-time user of tapestry, tapestry5 was really interesting. Sadly, it is not done yet, at all, and we need something now.
  • Struts2 has something going as it predecessor was really successful, but it really didn't score that well on the "fun factor" and RIA-easiness
  • SEAM is, well ... based on the horrible JSF
  • ZK loken very promising, but I had some actual experience with it, and it seemed a bit strange to work with and did not look the same on all platforms and browser
  • OpenLaszlo also looks promising but it is also much the same as flex is, and flex looks more complete and better documented. And, with Adobes latest open-source statements on the next flex, OpenLaszlo has lost some of its appeal to us. Only thing it has got left is its ability to render to multiple runtimes, but we do not need that (and will that ever work for real anyway?)
  • Applet - does anyone ever use this for real applications? If an applet is to work in most browsers on most platforms, the client needs Suns plugin for applets, and with that comes the complete JRE. When the complete JRE is there, Swing with JWS seems more appealing to us
And that leaves
Taking out the ones mentioned above we were left with:
  • GWT
  • Flex/Flash
  • Swing/JWS
Luckily, the current iteration ends today and we are planning on doing a spike in the next, to evaluate these three contenders by doing some development of the upcoming RIA application in each framework. This is going to be interesting!

The left out ones
Of course there are others. In Java-land, there are literally hundreds. We feel we have taken the most interesting ones into consideration, but here is a bit of information on some others, that did not even make it to the list.
  • Echo2 and Wicket: I see them mostly as a special-cases of GWT. Yes, they are different, for instance Echo2 executes a lot of logic on the server-side. But basically, they can help us in the same way as GWT can with producing RIA-applications, and GWT has got google backing
  • JSF: So screaming old-style a way to do web development! Abolutely no innovation in this framework. Only plus-thing is its industry backing and tool support. But that is not enough.
  • Tapestry 4: It is nice, yes. But it would not score high on "RIA easiness" and, it is highly incompatible with the upcoming tapestry5. If one is starting a Tapestry project today, it should be on v5.
  • WebWork: Well, it is struts2 now
  • Spring Web: I think spring should stop doing the complete stack and stick to what it has done well. Simple put!
  • RIFE: Simply too much more than simply a web framework.
Why not rails?
God knows, I love it :-) But, notice the emphazis I put on the "I". Not all love learning a complete new stack and moving to a new platform. Also, I and others have a lot of investment in the Java world. We are chosing a new web framework yes, but it is going to interoperate with a large existing JEE application.