Friday, May 30, 2008

Thi(e)s(e) (2.5) Week(s) in Wonder

ERCoreBusinessLogic has a nice new generic audit trail mechanism in the form of ERCAuditTrail. More documentation to come soon on this.

Chainable sort orders via ERXSortOrder (and/or ERXKey's sort order methods). For instance, you can do:

NSArray sortOrders = Person.LAST_NAME.asc().then(Person.FIRST_NAME).asc()).array();

ERXKey has "plural forms" of the sort order methods. For instance, Person.FIRST_NAME.ascs() (the "s" on the end will give you an NSArray containing a single eosortordering that represents "firstName asc") -- this is just a sort-cut for cases where you just have a single EOSortOrdering that you want to pass to a fetch spec.

AjaxSubmitButton can perform a partial submit without having an updateContainerID specified now (which really could be considered a bug, which I usually don't list here, but it's handy to know). So it behaves similarly to AjaxUpdateLink and AjaxSubmitButton's without a partial submit in that it will turn into a background request only.

You can now control Ajax resource insertion by providing a delegate to ERXResponseRewriter via ERXResponseRewriter.setDelegate(yourDelegate). See ERXResponseRewriter.Delegate. This lets you override when the framework (or other code) asks to include "Ajax" "prototype.js" and instead replace it for your own custom resource. For instance, if you want to bundle all your js into a single file, you can provide a delegate that overrides requests for any of the individual files and instead use your custom ones, or replace files with a minimized version of the original which may only be used in production.

AjaxModalContainer got a bit of a face lift (this is quoted from my original post on wonder-disc:)

Previously if you put contents inside the container tag, it would always render, which could be really big if you have a repetition. Now you can set ajax=true, and it will fetch the contents in an Ajax request instead. If you set ajax=true, you must also provide an id binding.

Previously, all the Ajax requests that were happening were not tagged with the proper request header, so it made Ajax requests appear to the server to be non-ajax requests.

There is now an iBox.init() function that is exposed to allow reinitializing iBox. For instance, if you have iBoxes in an update
container, you will want to call this at the bottom of your container. We need to add a better, more generalized way, to address this problem at some point, because several of the libraries have similar requirements.

You really should carefully consider the use of the action binding. It does not execute as an Ajax request (I'm not sure why, but it's explicitly documented as such), which means you can burn your backtrack cache using it. The preferred method of use for modal container should really be external hrefs, direct contents, or the new ajax=true binding with contents. In fact, unless someone has an example where the action binding is valid (which is possible -- I just can't think of an example), I'm almost tempted to consider it deprecated, or at least the behavior might change to make it more like other action bindings on Ajax components.

Lastly, there's a new example in ModalContainerExample that shows AjaxModalContainer used inside a repetition with an ajax=true that contains a form that allows you to edit objects in the repetition.

Migrations support more batch operations. For instance, previously you had to call .create() on a table prior to calling .setPrimaryKey(..). The Migration API now keeps track of whether or not it has been created and will work the same either way. Additionally, there are some new methods on ERXMigrationTable that provide support for PK generation through the usual EOF routes.

ERXQualifierInSubquery provides support for fetching objects of an entity where one of its to-many relationships matches a given qualifier.

ERXJDBCUtilities has some more convenience methods for doing ResultSet manipulation (for use primarily in complex migrations) via processConnection and processResultSetRows (see the javadoc for more info on using). Mainly these guys take care of opening and closing JDBC resources for you based on EOF adaptors.

ERXKeyGlobalID provides support for serializable EOKeyGlobalID's.

There is a new "globalID" prototype for storing globalID values in other EO's that uses ERXKeyGlobalID.

Rather than set the 4 or 5 recommended EC locking Properties, you can now just set er.extensions.ERXEC.safeLocking=true which will set all the recommended values for you instead.

ERXExtensions.initApp and ERXExtensions.initEOF static methods have been added to support running Wonder in test cases and main methods without wrapping your code in ERXMainRunner or a WOApplication.

ERXQuicksilverQualifier is a KeyValueQualifier that compares values with ERXStringUtilities.quicksilverContains, which considers "QS" to be 'equal' to "QuickSilver" -- matches the original string as long as the letters appear in sequence, but not necessarily contiguous. This does _NOT_ work in EOF -- only in memory.

"wo:img" and "wo:image" are now built-in shortcuts for the inline bindings parser.

Friday, May 16, 2008

Last Year's Last 20 Weeks in Wonder

We'll resume our regularly scheduled This Week in Wonder soon, but I had to go through all the ChangeLogs back to last year's WOWODC to figure out what I wanted to talk about at this year's WOWODC. I thought I'd go ahead and post my notes. There's very little detail here, but it was about 5000 lines of commit logs between June 2007 and January 2008, so these are just the ones that stood out to me. I'm sure there's a inadvertent bias towards thing I worked on (and things at the beginning of the list when I wasn't yet totally annoyed by changelogs).

* Lots of 5.4 compatibility work

* AjaxPing - support very small Ajax poller that can refresh a larger container when the cache key changes
* AjaxInPlace - added support for link vs button submits + better support for being in an existing form
* AjaxLongResponse

* ERXClickableContainer - makes arbitrary elements into links
* ERXWORepetition EO support - if er.extensions.ERXWORepetition.eoSupport=true, GIDs will be used instead of hashcodes
* ERXFlickrBatchNavigation/AjaxFlickrBatchNavigation
* ERXComponent - handy component baseclass

* Wonder has slurped up JavaMonitor and wotaskd
* Lots of enhancements to JavaMonitor

* ERXJDBCConnectionAnalyzer (from GVC) to help debug when you have a connection problem
* Support for ordering adaptor operations (to support SQLServer)
* Put a nail in the coffin of editing context locking
* FrontBasePlugIn - predictable/stable constraint names (for use in migrations)
* Partial Entities (experimental) - more info
* JavaMemoryAdaptor - an in-memory "database" ... really handy for example apps and test cases

* LOTS of enhancements

* New ERXMigration baseclass for migrations that use SQL scripts
* Support for vendor-specific SQL scripts in script migrations
* ERXModelVersion is a top level class now
* Added new API-based migrations - ERXMigrationDatabase, ERXMigrationTable, ERXMigrationColumn

* ERXFullTextQualifier (if your database supports it)
* ERXQ - shortcut methods for lots of different ways of creating qualifiers
* ERXS - shortcut methods for lots of different ways of creating sort orderings

* Added support for // VALID on inline bindings

* New pluralizer for ERXLocalizer (ported from Rails)
* iPhone support in ERXBrowser
* Support for multiple connections in ERIMAdaptor
* Redesigned ERXCrypto to allow pluggable encryption algorithms
* Added support for encrypted properties
* ERXMutableURL
* ERXExpiringCache supports version numbers in addition to timeouts
* ERXStats / ERXStatisticsPage - much more powerful stats tracking
* Refuse new sessions on low memory
* ERXResourceManager supports WebServerResource versioning to control browser caching
* Finally a SINGLE Properties setting for default encoding - er.extensions.ERXApplication.DefaultEncoding
* Lots of enhancements to RuleModeler

New: ERAttachment.framework
Inspired by th attachment_fu rails gem. Provides drop-in support for attachments that can be easily stored locally as static resource, locally as proxied resources via a custom request handler, as in-database resources (not currently streamed out of the database, so this should really only be used for person icons and other small resources), or on S3 as remote resources. See package.html for more details.

ERAttachment, btw, might be my favorite framework in Wonder ... If you use in-database attachments, you're talking add one relationship to your entity and a almost-no-code migration, then drop an ERAttachmentUpload component in your edit page, and an ERAttachmentViewer in your view page, and that's it. Very high bang-for-the-buck.

New: ERChronic.framework
Natural language date parsing (well, assuming your "natural language" is English). Direct port of Chronic from ruby (see and package.html for more details).

New: ERCaching.framework
Support for memcached with WO. I don't actually use this one yet, so Anjo can fill in more info here.

Friday, May 9, 2008

This Week in Wonder

Not the most exciting Week in Wonder, but they can't ALL be awesome :)

Attachments in BugTracker are now based on ERAttachments, and ERTags support has been added.

Migrations now support creating blob columns without specifying a size (it appears most databases don't require it).

Migrations should work much more reliably with Derby.

Unique index declarations for Migrations now support passing the index length, which is necessary to support indexes on MySQL (which cannot exceed certain lengths).

Certain Migrations are now declared to be optional, meaning a failure of the plugin to generate SQL will not result in an exception, but instead a log error. Foreign keys is an example, as not all database support foreign key constraints, but it's not really a failure condition.

Migrations now support adding regular indexes (rather than just unique indexes).

ERAttachments was converted from SQL-script-based migrations to api-based migrations. This should allow it to have much better support for other databases in the future.

AjaxObserveField has a new "observeDelay" binding that gives better periodic refresh behavior. This is particularly useful for textfields so that it doesn't fire as often as it would with just the regular frequency setting. With frequency, if a change occurred within the frequency period, a request will fire. WIth observeDelay, the request will only fire after the specified observeDelay amount of idle time. So as long as you're typing, it won't fire. When you pause, it will then fire.

If you spell the name of an update container ID wrong, you will now get a javascript error from your update links and submit buttons telling you the specified update container could not be found rather than just getting an update with no response.

Batch Fetching
ERXBatchingDisplayGroup and ERXRecursiveBatchFetching have much better batch fetching behavior for to-one relationships to abstract entities (read: it works now vs ... it didn't before).

ERXBatchingDisplayGroup now supports defining and using prefetching relationship key paths.

ERXBatchingDisplayGroup now supports overriding the row count manually. If you have a better method of setting the number of rows in the results compared to the display group's, you can now set it yourself. For instance, if you know you're only ever going to fetch two pages, you could set your row count to page size * 2 and the display group will 1) not fetch more than the row count you set and 2) skip executing the count(*) query, which can potentially be expensive. If you guess too high, it will correct for you when it runs out of rows.

Previously in OGNL, if you declared a helper function on a keypath and one of the elements of that keypath evaluated to null, WOOGNL was not able to identify which helper class to use. For instance, if you bound your value to "|dosomething" and person was null, it would not know to use StringHelper.dosomething(..). Now when this happens, it will walk the keypath to figure out what classes are in use and properly pass a null to your helper function. This allows you to make helpers that can do null replacement (similar to valueWhenEmpty on WOString, but in the general case).

Instead of using ERXKey.append, you can now use, which makes sense when you read your code out loud, but more importantly it's three characters shorter, which is kind of nice.

Saturday, May 3, 2008


Atlassian has provided a hosted FishEye for Project Wonder at

This Belated Week in Wonder

If you use databases sequences for PK generation that have an increment greater than one, you can now set er.extensions.ERXPrimaryKeyBatchSize or entity.userInfo.ERXPrimaryKeyBatchSize and Wonder will automatically provide a high-low implementation in memory. This can be a big performance gain for insert-intensive applications.

This was actually last week, but I forgot to mention it. Sometimes in migrations, you have to drop down and perform JDBC operations. A common one is adding a column and needing to set computed values for those rows. ERXJDBCUtilities.processResultSet can make this a little bit easier:

ERXJDBCUtilities.processResultSet(channel, "select id from SomeTable", new ERXJDBCUtilities.IResultSetDelegate() {
  public void processRow(EOAdaptorChannel rsChannel, ResultSet rs) throws Exception {
    int id = rs.getInt("id");
    ERXJDBCUtilities.executeUpdate(rsChannel, "update SomeTable set uuid = '" + something + "' where id = " + id);

There is now a longInt prototype added to ERPrototypes.

ERXQ and chainable qualifiers now have which will return the single object that matches the qualifier (or null if missing) or qualifier.requiredOne(array), which will do the same but throw an exception if it's not there. Additionally, you can call the variant qualifier.first(array), which will return the first object in the array (or null if there isn't one).

All qualifiers in Wonder now are chainable qualifiers.

ERXQ now provides the new shortcut methods .matches(..) (for regex qualification), .has(..) and .hasAtLeast(..) (for toMany qualifiers).

Often I find that it would be nice to not have my Properties defined inside my application bundle (so deployment of a new version is easier), but defining them in JavaMonitor can also be sort of annoying. Wonder now provides support for loading "machine global" properties. The default location for these Properties is /etc/WebObjects/[YourAppName]/Properties . You can change this default by setting er.extensions.ERXProperties.machinePropertiesPath .

There were a bunch of extensions and additions to ERRest so that it can be used as an EO simple syncing framework. It's not designed to handle conflict resolution (yet), but if you have multiple applications or deployments that need to all share a common set of EO's, ERRest makes it relatively easy to do this. For syncing, you should either be using UUID PK's or there should be a globally unique attribute on your EO. You setup your master side just like a normal REST setup (except that you should set -- like On the client, you can write:

EOEditingContext editingContext = ERXEC.newEditingContext();

ERXDefaultRestDelegate restDelegate = new ERXDefaultRestDelegate();
restDelegate.addDelegateForEntityNamed(new ERXUnsafeRestEntityDelegate(true), YourEntity1.ENTITY_NAME);
restDelegate.addDelegateForEntityNamed(new ERXUnsafeRestEntityDelegate(true), YourEntity2.ENTITY_NAME);
ERXRestContext restContext = new ERXRestContext(context(), editingContext, restDelegate);

String restPath = "Person";
URL remoteUrl = new URL("http://remotesite/rest/" + restPath + ".xml");
String contentStr = ERXFileUtilities.stringFromURL(remoteUrl);
ERXRestRequest restRequest = new ERXXmlRestRequestParser().parseRestRequest(restContext, contentStr, restPath);
ERXRestKey restResponse = restDelegate.process(restRequest, restContext);


This will sync all Person entities. You can sync arbitrary rest paths as well. For instance, in the example above, you could just as easily use a restPath of "Person/1231-23523-blah123234531-blah" to sync an individual person.

ERRest now also nested insertions, so you could have an update of a Person that does an insert of a new Company specified in the relationship. This is arbitrarily nested.

If you use the default separator in ERTaggable, it now supports parsing tags surrounded by quotes with multiple words. For instance, you can now tag your objects: tag1 tag2 "multiple word tag3".

ERSelenium now includes the necessary requirements for Selenium Remote Control -- see It's really cool.

AjaxSelectionList can now grab focus (focus = true) and has lots of misc fixes.

AjaxBusyIndicator can now watch a particular updateContainerID and either apply styles to that container, or perform custom onCreate and onComplete functions when a request occurs (note, this is onCreate of the request, and onComplete of the request, to explain the odd naming). This makes it easier to make per-component busy indicators that don't just trigger on every request.

AjaxPing now has an onBeforeUpdate binding that you can provide a Javascript function that can deny the update.

AjaxSubmitButton now has an elementName binding like AjaxUpdateLink. This allows you to make "clickable divs" (like ERXClickableComponent) that are Ajax submits.

Some of the Ajax components cached their generated ID values. These generated values were previously based on the component's element ID. The problem with this is that when the page structure changes, these components could be left hanging onto an ID that now belongs to another component on the page. These components now use a new scheme for ID generation that takes advantage of the new ERXResponseRewriter's page userInfo, to generate unique cacheable IDs.

ERXFlickrBatchNavigation now supports changing the batch size (showBatchSizes and batchSizes) bindings.

ERXCommandLineTokenizer provides a parser for parsing "command line"-style parameters, where individual words are single tokens as well as multiple words in double quotes or single quotes.


ERXFileUtilities.chmod(String, String) -- only works if you are on an OS that supports chmod

ERMovies was converted to migrations and should be a little easier to run out-of-the-box.