2011年2月16日 星期三

[Struts2] OGNL

* Object Graph Navigation Language

* Map是處理OGNL中最上層的物件(usually referred as a context map or context)。若是想取得其他物件,則必須要加上"#"符號,但若是 root object,則不需要加上此符號。

* struts2 中 OGNL context 為 ActionContext,value stack 為 OGNL 的 root object(The value stack is a set of several objects, but to OGNL it appears to be a single object.)。

* ActionContext 中除了 value stack,還有其他物件,例如:
                     |
                     |--application
                     |
                     |--session
       context map---|
                     |--value stack(root)
                     |
                     |--request
                     |
                     |--parameters
                     |
                     |--attr (searches page, request, session, then application scopes)

* The Action instance is always pushed onto the value stack. Because the Action is on the stack, and the stack is the OGNL root. 所以使用 Action instance 時不需要加"#",反之,若不是 root object,則必須加,例如:
 or
 or


* The ActionContext is also exposed to Action classes via a static method.
ActionContext.getContext().getSession().put("mySessionPropKey", mySessionObject);

* Syntax for list: {e1,e2,e3}.
// List containing the String "name1", "name2" and "name3". It also selects "name2" as the default value.


* Syntax for map: #{key1:value1,key2:value2}.


* To determine if an element exists in a Collection, use the operations in and not in.

   muhahaha


   boo


* use a wildcard within the collection:
? - All elements matching the selection logic
^ - Only the first element matching the selection logic
$ - Only the last element matching the selection logic

* To obtain a subset of just male relatives from the object person:
person.relatives.{? #this.gender == 'male'}

* OGNL supports basic lamba expression syntax enabling you to write simple functions.


* Under JSP 2.1 the # character is now used by the JSP EL.This may cause problems with some applications that use the OGNL # operator.


* Reference
- OGNL
- OGNL Basics
- C# 3.0 極簡風 - Lambda Expression
- Lambda 運算式 (C# 程式設計手冊)

沒有留言:

張貼留言