Wiki source code of Programming__WebObjects-Project WONDER-Frameworks-WOOgnl
Version 9.1 by smmccraw on 2007/07/08 09:45
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | == Overview == | ||
| 2 | |||
| 3 | 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>>http://www.ognl.org]]. | ||
| 4 | |||
| 5 | 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.,, | ||
| 6 | |||
| 7 | Here are some examples that demonstrate just a tiny bit of the really cool things you can do: | ||
| 8 | |||
| 9 | * value=",,Hello Mr. + session.user.firstName";,, | ||
| 10 | * value=",,name.length().(#this>100?2**#this:20+#this)";**,, | ||
| 11 | * value=",,#A=new NSMutableArray(),#A.addObject(name),#A";,, | ||
| 12 | |||
| 13 | Here are some examples provided by Max Muller, WOOgnl's original author: | ||
| 14 | |||
| 15 | {{panel}} | ||
| 16 | |||
| 17 | // Calling methods with arguments | ||
| 18 | Repetition1: WORepetition { | ||
| 19 | item = arrayItem; | ||
| 20 | list = "~sort(anArray, \"name\")"; | ||
| 21 | } | ||
| 22 | |||
| 23 | {{/panel}} | ||
| 24 | |||
| 25 | ~/~/ Calling static methods | ||
| 26 | |||
| 27 | {{panel}} | ||
| 28 | |||
| 29 | Repetition2: WORepetition { | ||
| 30 | item = arrayItem; | ||
| 31 | list = "~@er.extensions.ERXArrayUtilities@sortedArraySortedWithKey(anArray, \"name\")"; | ||
| 32 | } | ||
| 33 | |||
| 34 | {{/panel}} | ||
| 35 | |||
| 36 | ~/~/ Accessing static ivars | ||
| 37 | |||
| 38 | {{panel}} | ||
| 39 | |||
| 40 | String1: WOString { | ||
| 41 | value = "~@ognl.webobjects.WOOgnl@OgnlSpecialCharacters"; | ||
| 42 | } | ||
| 43 | |||
| 44 | {{/panel}} | ||
| 45 | |||
| 46 | ~/~/ Use of conditionals, note that every previous value of the . is | ||
| 47 | |||
| 48 | {{panel}} | ||
| 49 | |||
| 50 | // pushed into the ivar #this | ||
| 51 | String2: WOString { | ||
| 52 | value = "~name.length().(#this > 100? 2*#this : 20+#this)"; | ||
| 53 | } | ||
| 54 | |||
| 55 | {{/panel}} | ||
| 56 | |||
| 57 | ~/~/ String concat | ||
| 58 | |||
| 59 | {{panel}} | ||
| 60 | |||
| 61 | String3: WOString { | ||
| 62 | value = "~\"Hello Max \" + name"; | ||
| 63 | } | ||
| 64 | |||
| 65 | {{/panel}} | ||
| 66 | |||
| 67 | ~/~/ Use of set operator in. can also use in against NSArray and | ||
| 68 | |||
| 69 | {{panel}} | ||
| 70 | |||
| 71 | NSSet objects | ||
| 72 | String4: WOString { | ||
| 73 | value = "~name in {\"Main\", \"Something\"} ? \"Yes\" : \"No\""; | ||
| 74 | } | ||
| 75 | |||
| 76 | {{/panel}} | ||
| 77 | |||
| 78 | ~/~/ Variable declaration. Note that commas allow multiple actions | ||
| 79 | |||
| 80 | {{panel}} | ||
| 81 | |||
| 82 | // per expression. | ||
| 83 | String5: WOString { | ||
| 84 | value = "~#A=new com.webobjects.foundation.NSMutableArray(),#A.addObject(name), #A.addObjectsFromArray(session.languages), #A"; | ||
| 85 | } | ||
| 86 | |||
| 87 | {{/panel}} | ||
| 88 | |||
| 89 | Category:WebObjects |