跳轉到內容

WebObjects/Project WONDER/Frameworks/WOOgnl

來自華夏公益教科書,開放的書籍,開放的世界

WebObjects 華夏公益教科書頁面被認為已過時

[編輯 | 編輯原始碼]

轉至 http://wiki.objectstyle.org/confluence/display/WO/Project+WONDER-Frameworks-WOOgnl

OGNL 代表“物件圖導航語言”,它定義了整個鍵值編碼類能力系列。正如 Jonathan Rentzsch 在其關於 Project WOnder 的 CAWUG 演示中所說,“想想:類固醇上的鍵值編碼”。你可以在 官方 OGNL 網站 上找到更多關於 OGNL 細節的資訊。

WOOgnl 提供了一個框架,它將 OGNL 語法整合到 WO 的標準繫結解析中。只需在你的構建路徑中包含 WOOgnl 框架並在你的繫結值之前新增“~”,它將被 WOOgnl 解釋。

如果你的 html 標記格式正確,你也可以在標準 html 標籤中放置 ognl 表示式,如果你設定了以下屬性

ognl.parseStandardTags=true

以下是一些例子,展示了你可以用它做的一些非常酷的事情

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

以下是一些由 WOOgnl 的原始作者 Max Muller 提供的例子

 // 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 com.webobjects.foundation.NSMutableArray(),#A.addObject(name), #A.addObjectsFromArray(session.languages), #A";
 }
華夏公益教科書