Wiki source code of WOOgnl Framework

Version 20.1 by Pascal Robert on 2012/08/27 13:18

Show last authors
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://commons.apache.org/ognl/]].
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 {{code}}
16
17 // Calling methods with arguments
18 Repetition1: WORepetition {
19 item = arrayItem;
20 list = "~sort(anArray, \"name\")";
21
22
23 {{/code}}
24
25 {{code}}
26
27 // Calling static methods
28 Repetition2: WORepetition {
29 item = arrayItem;
30 list = "~@er.extensions.ERXArrayUtilities@sortedArraySortedWithKey(anArray, \"name\")";
31 }
32
33 {{/code}}
34
35 {{code}}
36
37 // Accessing static ivars
38 String1: WOString {
39 value = "~@ognl.webobjects.WOOgnl@OgnlSpecialCharacters";
40 }
41
42 {{/code}}
43
44 {{code}}
45
46 // Accessing static ivars within inner class
47 String1: WOString {
48 value = "~@ognl.webobjects.WOOgnl$MyInnerClass@OgnlSpecialCharacters";
49 }
50
51 {{/code}}
52
53 {{code}}
54
55 // Use of conditionals, note that every previous value of the . is
56 // pushed into the ivar #this
57 String2: WOString {
58 value = "~name.length().(#this > 100? 2*#this : 20+#this)";
59 }
60
61 {{/code}}
62
63 {{code}}
64
65 // String concat
66 String3: WOString {
67 value = "~\"Hello Max \" + name";
68
69
70 {{/code}}
71
72 {{code}}
73
74 // Use of set operator in. can also use in against NSArray and
75 NSSet objects
76 String4: WOString {
77 value = "~name in {\"Main\", \"Something\"} ? \"Yes\" : \"No\"";
78 }
79
80 {{/code}}
81
82 {{code}}
83
84 // Variable declaration. Note that commas allow multiple actions
85 // per expression.
86 String5: WOString {
87 value = "~#A=new com.webobjects.foundation.NSMutableArray(),#A.addObject(name), #A.addObjectsFromArray(session.languages), #A";
88 }
89
90 {{/code}}
91
92 === Helper system ===
93
94 For more detail, check [[documentation:WOOGNL Helper Functions]]. With these two lines in your properties file and Project WONDER,
95
96 {{code}}
97
98 ognl.helperFunctions=true
99 ognl.inlineBindings=true
100
101 {{/code}}
102
103 You can declare your own helper class like this:
104
105 {{code}}
106
107 public class StringHelper {
108 public String capitalize(String str) {
109 // ...
110 }
111 }
112
113 {{/code}}
114
115 And use that in your binding by "piping your data"
116
117 {{code}}
118
119 <wo:str value="$person.name|capitalize" />
120
121 {{/code}}