存取Value Stack的方式
---------------------
1. Using tags on Jsps,Velocity,Freemarker
2. HTML tags access properties of objects from the value stack;
3. Control tags (ex: if , else , iterator .. etc) are used with expressions.
4. Data tags are available to manipulate the stack itself (via set and push).
在存取value stack時,其實不用去特別注意該object是存在於哪一個範圍內的
(ex: session , request),假設要找的是attribute "name",那就是直接跟value stack
要這個attr即可!
如果要找的attr不存在?
If not, then the next element down is queried.
This continues until the end of the stack is reached. This is a great feature,
as you don’t care where the value is – the action, the model,
or the HTTP request – you just know that if the value exists it will be returned.
但這樣仍然會有些缺點,如果property是很常見的, 像是 "id",而你需要在特定的範圍中存取,
那嚜我們可以透過OGNL的特性來處理,根據你的存取範圍的深度去取,假設我要取的"id"是存放在action中,那嚜就可以使用 [2].id來處理,而非用一般的 "id"。
<hr/>
事實上,OGNL也是一種 expression language。
As well as using dot notation to navigate object graphs
(i.e. using“person.address” instead of “getPerson().getAddress()”
as the expression), OGNL supports features such as type conversion,
calling methods, collection manipulation and generation,
projection across collections, expression evaluation and lambda
expressions .
<hr/>
Result Types
Result type 指的是在 action 的設定中,指定的result type tag。
一般如果沒有特別指定的話,都是設定為 "dispatcher"。
<action name="my" class="com.fdar.infoq.MyAction" >
<result type="dispatcher">view.jsp</result>
</action>
Result types是在 <package /> tag中設定的,方式跟先前提到的interceptor 很類似。
<result-types>
<result-type name="dispatcher" default="true"
class="….dispatcher.ServletDispatcherResult"/>
<result-type name="redirect"
class="….dispatcher.ServletRedirectResult"/>
…
</result-types>
自行實作Result Types
public interface Result extends Serializable{
public void execute(ActionInvocation invocation)throws Exception;
}
The ActionInvocation object provides access to the runtime
environment, allowing the new result type to access information
from the action that was just executed, as well as the context in
which the action was executed. The context includes the
HttpServletRequest object, which provides access to the
output stream for the current request.
沒有留言:
張貼留言