WO Wideos

Seems like video is the new black in the WO community this week with the Ajax.framework from Project Wonder taking front billing.

Mike Schrag has posted a short video showing how to create and Ajaxify a new WebObjects app demonstrating some of the new features coming to WOLips.

John Larson has posted a YouTube video of some of the stuff he’s done leveraging the Ajax.framework.

Migration to Velocity EOGenerator Complete

With the release of Leopard, I was saddened to learn that we’d lost the use of EOGenerator in the resulting tools deprecations. Thankfully, a couple of major competitors filling that role quickly arose.

I’d mentioned JavaEOGenerator before but after working with it for a bit I decided to go with the Velocity based EOGenerator (veogen) built into WOLips.

I’m happy to report that as of WOLips build 3.3.4778 all of the pieces are in place in the veogen engine to duplicate my existing EOGenerator templates (the last missing bit was the named and typed bindings for fetch specs).

Veogen works very well. It is a lot faster than the old EOGenerator and I didn’t find the template language difficult to figure out.

For those moving to veogen, the built in templates are pretty comprehensive but if you feel the need to customize, there are a number of templates on the wiki to help get you started. The wiki also contains a fairly comprehensive list of the available bindings here.

Go forth and generate.

Leopard: WebObjects Notes

Leopard is out and with it comes a slew of WebObjects changes. The release of WO 5.4, the official deprecation of the tool chain (which we’ve known was coming for some time), Apache 2 support, etc.

There’ve been some posts to the webobjects-dev list which I consider required reading. I don’t know if this stuff has made it into the wiki yet, so here are some links:

So, lots going on, and it all looks good IMHO. Should be a good year for WO.

Notes:

  • The permissions on /Library/WebObjects/Configuration needed to be fixed otherwise wotaskd and javamonitor barf.
  • /System/Library/WebObjects/Executables/WOOpenURL seems to be missing. I copied it from the WO53 install and that works. Upate: It turns out that it’s not needed for WO54, it just uses the open command.

Just a few of my favorite things…

Project Wonder is chocked so full of WebObjects goodness that it is hard to envision developing a project without it. Here are three bits that I use all the time.

Autolocking EditingContexts

Step one: Learn WebObjects

Step two: Realize that using the session().defaultEditingContext() exclusively is bad.

Step three: Start using multiple EOEditingContexts.

Step four: Read, re-read, then read again the documentation on EC locking.

Step five: Encounter production deadlocks.

Step six: Cry.

Thankfully Project Wonder provides an amazing solution in the form of autolocking EditingContexts. Enabling them is simple. Set some properties for your project:

er.extensions.ERXApplication.useEditingContextUnlocker=true
er.extensions.ERXEC.defaultAutomaticLockUnlock=true
er.extensions.ERXEC.useSharedEditingContext=false
er.extensions.ERXEC.defaultCoalesceAutoLocks=true

There is an email from Mike Schrag with some juicy details here.

Change your code so that you never call new EOEditingContext(); instead use the ERXEC.newEditingContext() factory method.

ERXThreadStorage

Problem: You need access to an object in your session from an EO. Maybe you want to set a “createdBy” value to the current user in awakeFromInsertion

Adding a reference to the Session in your EOs would be bad so what are you going to do?

Solution: Use ERXThreadStorage to store a reference to the current user and access that from your EO.

In your Session.java:

public User currentUser; // assume exists

public void awake() {
    super.awake();
    ERXThreadStorage.takeValueForKey(currentUser, "currentUser");
}

In your EO.java:

public void awakeFromInsertion(EOEditingContext ec) {
    super.awakeFromInsertion(ec);
    User user = ERXThreadStorage.valueForKey("currentUser"));
    if (user != null) {
        setCreatedBy(user.userName);
    }
}

ERXGenericRecord

ERXGenericRecord is another Project Wonder class that is full of yumminess. Please read the API docs for the full details, but here are a few of my favorites:

willUpdate(); // called after saveChanges() but before validation
              // so it is safe to make changes. See the rest of
              // will* and did* methods for more

primaryKey(); // returns the primary key (null if the EO hasn't
              // been saved yet)

primaryKeyInTransaction(); // returns the primary key as above,
              // but if the EO hasn't beens saved yet, it'll
              // figure out what the pk should be, return it,
              // cache it, and use it later when the EO does get
              // saved. Very cool.

There is much, much more: ERXLocalizer, ERJavaMail, ERExcelLook… Dive into the docs and I’m sure you’ll find something usefull.