* tag 是為了顯示動態資料,例如:
textfield 會帶入屬性 postalCode 的值(call getPostalCode()),相對的,若 value stack 中有此屬性,在頁面 submit 後,此 textfield 的值便會被設定會此屬性(call setPostalCode())。
* 動態顯示 tag 相關資訊,例如:
藉 application's messages resources,得到 text label at runtime,framework 會轉換 key 中的 expression 找到相對應的資訊。
任何以 "%{ ... }" 表示的都會被視為 expression。在 struts2 中默許的 expression language 是 OGNL,而能呼叫 method and property,例如 base class ActionSupport 中的 getText()。因為 Action 在 stack 中,所以能藉 expression 呼叫使用其中的 method。例如:
* The HTTP protocol is text-base.
* the framework evaluates
all non-String attributes as an expression. 例如以下三種寫法,皆可:
// verbose
// with property
// verbose with property
*
value is an Object: 通常 framework 會透過 name 去呼叫設定相對應屬性,然後自動帶入 value,因此若 value 被直接指定了,表示的是一個物件。
// Probably wrong!! 因為 value 非字串,所以不管指定什麼都視為 expression,也就是會被看成 %{ca}
// 所以若是想傳一個屬性名稱為 ca 的字串,則必須再加上單引號
*
Overview: the tag attributes evaluated using rules:
- All String attribute types are parsed for the "%{ ... }" notation.
- All non-String attribute types are not parsed, but evaluated directly as an expression
- The exception to rule #2 is that if the non-String attribute uses the escape notion "%{}", the notation is ignored as redundant, and the content evaluated.
* Expression Language Notations
// A JavaBean object in a standard context in Freemarker, Velocity, or JSTL EL (Not OGNL).
Username: ${user.username}
// A username property on the Value Stack.
// Another way to refer to a property placed on the Value Stack.
es
Espanol
// The username property of the User object in the Session context.
// A static Map, as in put("username","trillian").
* Reference
-
Tag Syntax
-
STRUTS2 TAG 語法
-
Struts 2 key attribute example
-
Message Resource Files