Open main menu

Wikibooks β

WebObjects/Project WONDER/Frameworks/WOOgnl

< WebObjects‎ | Project WONDER

WebObjects WikiBooks pages considered deprecatedEdit


OGNL stands for "Object Graph Navigation Language", and it defines an entire family of key-value coding-like abilities. As Jonathan Rentzsch put it in his CAWUG presentation on Project WOnder, "Think: Key-Value Coding on Steroids". You can get more information on the specifics on OGNL at the official OGNL website.

WOOgnl provides a framework that integrates the OGNL syntax into WO's standard binding resolution. By simply including the WOOgnl framework on your build path and preceding your binding value with a "~", it will be interpreted by WOOgnl.

Provided your html markup is well-formed, you can also put ognl expressions in standard html tags if you set the following property:


Here are some examples that demonstrate just a tiny bit of the really cool things you can do:

  • value="~\"Hello Mr.\" + session.user.firstName";
  • value="~name.length().(#this>100?2*#this:20+#this)";
  • value="~#A=new NSMutableArray(),#A.addObject(name),#A";

Here are some examples provided by Max Muller, WOOgnl's original author:

 // Calling methods with arguments
 Repetition1: WORepetition {
       item = arrayItem; 
       list = "~sort(anArray, \"name\")"; 
 // Calling static methods
 Repetition2: WORepetition {
       item = arrayItem; 
       list = "~@er.extensions.ERXArrayUtilities@sortedArraySortedWithKey(anArray, \"name\")"; 
 // Accessing static ivars
 String1: WOString {
       value = "~@ognl.webobjects.WOOgnl@OgnlSpecialCharacters";
 // Use of conditionals, note that every previous value of the . is
 // pushed into the ivar #this
 String2: WOString {
       value = "~name.length().(#this > 100? 2*#this : 20+#this)";
 // String concat
 String3: WOString {
       value = "~\"Hello Max \" + name";
 // Use of set operator in.  can also use in against NSArray and
 NSSet objects
 String4: WOString {
       value = "~name in {\"Main\", \"Something\"} ? \"Yes\" : \"No\"";
 // Variable declaration.  Note that commas allow multiple actions
 // per expression.
 String5: WOString {
       value = "~#A=new,#A.addObject(name), #A.addObjectsFromArray(session.languages), #A";