顯示具有 Struts2 標籤的文章。 顯示所有文章
顯示具有 Struts2 標籤的文章。 顯示所有文章

2013年9月18日 星期三

[Struts2] Interceptor

struts2 重點在於加入 MVC
所以 interceptor 是和 struts1 很大的不同處


struts2 中有預設的 interceptor
package struts-default
name defaultStack

當我們的 package extends struts-default 就繼承了 struts-default 中的所有設定!


ActionInvocation: 包裝所有與 Action 執行有關資訊的物件
在開發 interceptor 時,我們並不會直接的與 ActionInvocation 物件互動,而是間接的與 ActionInvocation 有關係!
當我們的 framework 接收到一個使用者的 request 時,Struts2 framework 會根據使用者呼叫的 URL 來 mapping 所對應的 Action,並將此 Action 的相關資訊加入到 ActionInvocation 物件中,接著 Struts2 framework 就會搜尋所有 configuration file 中的所有 interceptors 並且加到 ActionInvocation 中,幫助 ActionInvocation 走訪所有的 interceptors。



    
    
        
    
     .......

    
    
        
    

    
    
        
            dojo\..*        
    
      ..........     





    
    
    /WEB-INF/pages/finish.jsp



* Reference
- [Struts2] Introduce Interceptor
- [Struts2] 宣告與設定 Interceptors
- [Struts2] 深入探討 Interceptor

2012年6月22日 星期五

[Web] Brief notes


  • slf4j
    • 在 jar 檔時就 binding,比較好切換。
  • framework
    • 提供 pattern 的模組
  • Spring framework
    • 本身是個大 factory,將工作交給底下的 factory...
  • Struts2
    • #attribute 作用約是 ${attribute}
  • iBatis
    • $var$
      • paraClass 中的 attribute
    • #fieldName:fieldType#
      • Table field
  • HTML
    • 由上而下 compiler,結果會是 DOM tree 結構。
    • DTD
      • 描述 HTML syntax
    • <meta>
      • 提供和 browser or search engine 相關的訊息。
      • ex: 描述文檔的內容。

2012年2月14日 星期二

[HTML] Checkbox with Spring or Apache Struts

checkbox 回傳至 server 值如: [1,2,3],ex: List setObjectAttribute(...) {}

可能會收到 [, 2] 這類含有空值的設定值;當 checkboxlist 完全未選擇時,設定值會為 []。


SpringFramework:

<input type="hidden" name="_peopleGroupTags" value="on" />

Apache Struts 2:

Fix for https://issues.apache.org/jira/browse/WW-992

<s:hidden id="
attributeName_0" name="attributeName" value="" />

2011年10月1日 星期六

[Struts] action and jsp


    jsp file path

method: 指定要去執行的 method。

result: 是 action 裡指定要對應到頁面的字串。

[Struts2] s:hidden

<s:hidden name="parentCategoryId" id="parentCategoryId"></s:hidden>

不用指定 value 便會將值塞進去

[J2EE] action, controller and servlet

action = controller = servlet

2011年9月24日 星期六

2011年4月6日 星期三

2011年2月25日 星期五

Internationalization

* 在 struts.xml 中可以設定 interceptor,指定抓取特定參數與想對應處理的 class,且會將此值存入 session。

* http request 預設參數為: request_locale

* JSP 欲取 properties 時,便可因此知道該使用那種語系


* Reference
Struts 2 – i18n or localization example
Interceptors
Struts2学习笔记(7)--Internationalization - 纸飞机 - 51CTO技术博客
I18nInterceptor (Struts 2 Core 2.1.2 API)
Struts 2 国际化 [Localization] (转) - Tony的日志 - 网易博客

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# 程式設計手冊)

2011年2月12日 星期六

[Struts2] Tag Syntax

* 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