Practical WebObjects

A new WebObjects book by Charles (Chuck) Hill and Sacha Mallais arrived on my doorstep last week (literaly, Steve accidentally ordered two copies, and I benefited from his Amazon click happiness). Practical WebObjects is aimed at intermediate WebObjects developers and I think it succeeds nicely. From talking about integrating Unit testing and contract programming to examples of Kerberos authentication it offers plenty of practical examples and lots of stuff to think about.

Not having taken the WebObjects courses offered by Apple (and others), I’ve done the majority of my learning relying on books, the web, the docs, and playing. Practical WebObjects is a solid book that adds depth to the existing offerings. I wouldn’t suggest it as a first book to someone getting started (Joshua Markers Visual Quick Pro Guide and Apple’s Tutorial are a better bet there) but for someone who is looking to expand their horizons or for a best practices guide I think it does an admirable job.

Thanks Chuck and Sacha!

Java 1.4 regex fun

I’m sure that everyone knows that Java 1.4 added regex capabilities through the java.util.regex package. I have existing applications using regex (from Jakarta Oro) that were built pre Java 1.4 so I haven’t looked at this support closely until now.

What I hadn’t realized was that you don’t need to use the Pattern or Matcher classes in java.util.regex to do simple regex substitutions, that capability is built right into java.lang.string!

An example of this usage would be formating phone numbers for storage or display. I usually like to store phone numbers as 10 character strings, and apply formating when they are displayed. This is easy using regex substitution. To format for storage:

String source = "(555) 555-5555";
String result = source.replaceAll("^1|\\D+", "");

The result will be "5555555555".

Conversely, to format for display:

String source = "5555555555;
String result = source.replaceAll("^(\\d{3})(\\d{3})(\\d{4})", 
				  "($1) $2-$3");

The result will be "(555) 555-5555".

The documentation for String.replaceAll is here and it is fairly straight forward:

public String replaceAll(String regex,
                         String replacement)

The first example used the regex: "^1|\\D+"  It says; match the first character if it is a "1" (^1) OR (|) any character that is not a number (\\D+) and replace with "" (the replacement).

The second example used the regex: "^(\\d{3})(\\d{3})(\\d{4})"  It says; match the first 3 characters and put them into a variable ($1) do the same for the next 3 ($2) and the final 4 ($3). Then using the replacement: "($1) $2-$3" wrap the contents of $1 with "()" add a space and the contents of $2, followed by a "-" and the contents of $3.

A good regex primer can be found here

Eclipse/WOLips

I have Eclipse/WOLips working (Eclipse 2.1.3 with WOLips 1.0.7.50 on OS X Panther). Eclipse is a very nice Java IDE, providing many features that Xcode currently is missing for WebObjects/Java development (re-factoring tools, code completion, etc) and without some of Xcode’s peculiarities (indexing anyone?).

I had to struggle a bit to get it going, but with help from a couple of lists [ A , B ] I’ve got it all straightened out.

Here are a few things I ran into that might help someone else:

  • Apply the WebObjects 5.2 hack found here. I made copies of the required frameworks into /System/Library/PrivateFrameworks_Disabled/ and then linked the correct ones into /System/Library/PrivateFrameworks/ so I can easily switch back and forth if I need to change IDE’s.
  • Do not try Eclipse 3.0 M* with WOLips – It’s really not ready… really.
  • Remove the Apache Xerces.jar from your class path – It will crash Eclipse 2.1.3 and cause you to waste an entire day discovering how really not ready Eclipse 3.0 M* is… Oh, yeah, this is documented in the Eclipse/WOLips help section… once you get Eclipse running. OK, its on the WOLips website too, but who would think to look there? Honestly.
  • Apply the Eclipse org.eclipse.core.ant patch found here
  • To add Webserver Resources (like images, etc) you need to do two things:
    First, add them to the wsresources section of the build.xml file so it looks something like this:

    <wsresources dir=".">
    	<include name="*.jpg"/>
    	<include name="*.gif"/>
    	<exclude name="**/*.woa/**"/>
    </wsresources>

    Then, go to: Eclipse -> Window -> Preferences -> WOLips -> ProjectBuilder -> WOApp Resources Include and add *.jpg, *.gif, etc. to the list.

I think that’s it for now, I’ll post more if I come across it..

Whoo hoo! WebObjects 5.2.3 is out!

According to the technote this update offers a number of fixes:

This update address issues with CLOSE_WAIT states in deployment using JavaMonitor and wotaskd. It also addresses a number of issues related to EOF under high load.

But most importantly it is fully qualified for development and deployment on Panther with Java 1.4.2!

Now all I need is qualified version of Project WONDER..

UPDATE: As noted by Art Isbell on the WebObjects-dev list this release requires Java 1.4.2… and the installer fails with an erroneous error message: "This update can be installed only on Mac OS X 10.3.3 or later." if you are trying to install on Panther with Java 1.4.1.

SwitchableStrings

One thing that I often end up creating in my WebObjects projects are details/edit components for my entities. For instance I might have a User details page that has a edit action allowing you to switch from a static display to a form for editing.

This usually requires duplicating the layout with WOStrings (etc) for the static view and WOTextFields (etc) for the form.

Paul Suh has come to my rescue by creating a framework called SwitchableStrings. These are drop in replacemnts for the standard WebObject form elements that have the addition of an editable binding. When the binding is true they display form elements, and when false they display static ones.

Sweet!