Sam Newman's site, a Consultant at ThoughtWorks

I’ve been looking into this whole XWork + Swing thing a little more, and have come up with a fairly simplistic example of how a Swing+XWork framework might look. If you want to follow the code I suggest you read my brief “XWork tutorial(A Simple Xwork Example)”: Anyway, my example shows a simple window with a button and a progress bar. When clicked, the button invokes an XWork Action on a thread. A ProgressInterceptor records when the action starts and ends, and changes the state of the onscreen progress bar as appropriate.

The Action has to be run on a seperate thread, as otherwise it will be invoked on the Event thread, blocking any GUI updates until the action has returned. This means that the return from Action‘s execute method cannot be handled – we have moved from synchronous action invocation to asynchronous action invocation. The ProgressInterceptor calls methods on aProgressRegister singleton to tell it when an Action has started or stopped. I dislike the use of a singleton, but right now it is impossible to pass objects into an Interceptor (this is a nasty constraint of XWork – I might see how easy it would be to use Spring to create Interceptors). A ProgressListener gets registered with the ProgressRegister, and updates a JProgressBar as required.

Its actually a lot simpler than it sounds – check the code for yourself to see. It represents an afternoon of work so is a little rough and ready – you’ve been warned! To run the program the main class is org.magpiebrain.example.TestProgram. The code requires webwork1.0, OSCore, OGNL and commons-logging to run, all of which are included in the zipfile. If I decide to take this much further I will look into supporting SWT, so suggestions as to how easy this would be are welcome. Note that the only GUI feedback from the action is by the progress bar at present – I need to think about the interaction between the result of the Action and its impact on the GUI a little more.

8 Responses to “A GUI framework using XWork”

  1. Fernando Martins

    I guess you mean xwork1.0 an not webwork1.0.
    Anyway, that is all very nice, but I’de really like to see Remote Xwork Action invocation. There is some work started on this (see
    and although it’s webwork based, I think could be striped of ww dependencies and be able to provide
    a Xwork clean way of invoquing action remotely.
    I hope to have some time soon, to work on this, and provide a few simple samples…

  2. Sam Newman

    Yep, meant webwork not xwork 🙂 Remote XWork invocation shouldn’t be too hard – I’m guessing you just need to use an ActionInvocation as a proxy wrapping underlying RMI calls. The JIRA link you provided doesn’t work by the way.

  3. Stuart Ervine

    Your idea for a swing framework looks pretty good, and I came across it because I was thinking about producing something similar – but figured someone must have done it before.

    After many hours searching the web however, I came up with zip and started out by coding my own. I am currently still throwing ideas around – but something I was quite keen on introducing was a way of ‘binding’ component value properties to their corresponding action properties. This technique has been used by the likes of webwork and tapestry.

    I’m going to keep pushing on with my code, but your idea definitely sounds as if it could be more robust, and I look forward to seeing more of it!

  4. Ryan Sonnek

    I just read your blog, and was quite intrigued. I started a project called SwingWork a couple monthes ago with the hope to flesh out a more comfortable execution environment for XWork and Swing. I would be very interested to hear your comments (and if you’re interested involvement) with this project!

  5. Sam Newman

    I’d certainly like to look at what you’ve done Ryan, although as far as getting involved goes my plate is very full – I’m currently working on a NakedObject’s related project. In fact it sounds like your work may be of use further down the road.

  6. Stuart Ervine

    I had a look at the Spring-RCP (or Rich C), and although Keith has done a great job so far, I was a bit confused about how to handle an application which required posting results to new panels in say… a tabcontainer.
    So I picked up on where I’d left off and have pushed on with the development of an XWork based framework. It’s now on it’s first Release Candidate and if you’re at all interested, it’s available at:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Basic HTML is allowed. Your email address will not be published.

Subscribe to this comment feed via RSS

%d bloggers like this: