Chuyên đề Báo cáo SEMINAR STRUTS 2

Có những lúc chúng ta muốn các interceptor của chúng ta thực hiện theo một thức tự và sữ dụng nhiều lần cùng một thứ tự đó thì nếu dùng cách khai báo từng interceptor trong mỗi action thì sẽ dư thừa. Do đó trong struts2 có khái niểm stack để chúng ta khai báo thứ tự của các interceptor mình sẽ dùng.

doc53 trang | Chia sẻ: lylyngoc | Lượt xem: 2890 | Lượt tải: 0download
Bạn đang xem trước 20 trang tài liệu Chuyên đề Báo cáo SEMINAR STRUTS 2, để xem tài liệu hoàn chỉnh bạn click vào nút DOWNLOAD ở trên
ên nó thừa hưởng được đầy đủ các ưu điểm mà mô hình MVC đem lại. - Dễ dàng tùy chỉnh (customize) chu kỳ xử lý (request lifecycles ) cho từng action - Giải quyết hiệu quả vấn đề internationlization và localization trong các ứng dụng web - Tự động chuyển đổi kiểu dữ liệu chuỗi truyền thống trong tham số request parameter thành các đối tượng lớp dữ liệu java => tiết kiệm được thời gian và công sức cho các lập trình viên - Cung cấp các thẻ tag,các themes và templates giúp cho việc làm giao diện GUI trở nên dễ dàng,nhanh lẹ và tăng tính tái sử dụng. - Tính mở rộng (Extensibility) cao thông qua việc hỗ trợ các plug-in - Hỗ trợ portal - Hỗ trợ AJAX - Dễ dàng tích hợp với Spring framework và Hibernate. Kiến trúc và hoạt động của Struts 2 Kiến trúc của Struts 2 framework Hình 1: Kiến Trúc Của Struts 2 Framework ActionContextCleanup : là tùy chọn và được sử dụng khi tích hợp với các công nghệ như SiteMash Plugin. FilterDepatcher: là bộ lọc nó Sử dụng ActionMapper để xác định xem Action nào được call và sau đó giao quyền lại cho ActionProxy ActionProxy: lấy những action từ struts.xml qua sự giúp đỡ của ConfigurationManager từ đó tạo ra những ActionInvocation thực hiện gọi Action mà ta đã config trong struts.xml trước đó nó gọi tới những interceptor (nếu được config). Và sau đó lấy về kết quả thích hợp tái tạo lại các trang jsp theo mẫu nào đó và trả về lại cho người dùng. Action là một lớp do developer tự định nghĩa, đây là lớp làm việc cơ bản , Là một POJO (Plain old java object) có phương thức execute() . Template: chứa kết quả trả về cho người dùng. Trong Struts2 nó là những result của Action được config trong struts.xml. Có một số loại result sau: Chain Result Dispatcher Result FreeMarker Result HttpHeader Result Redirect Result Redirect Action Result Stream Result Velocity Result XSL Result PlainText Result Quá trình xử lý request trong Struts2 framework Người sử dụng gửi yêu cầu đến server để yêu cầu một số tài nguyên của ứng dụng Bộ điều khiển lọc (FilterDispatcher) xem xét yêu cầu và sau đó xác định một Action thích hợp Các bộ chặn (Interceptors) được ứng dụng: các cấu hình bộ chặn áp dụng cho các chức năng chung như: luồng công việc, thẩm định, tải file … được tự động ứng dụng vào yêu cầu Thực thi Action: sau khi phương thức action được thực thi để thực hiện các hoạt động liên quan đến cơ sở dữ liệu như sắp xếp hoặc nhận dữ liệu từ cơ sở dữ liệu Sinh kết quả Sau đó kết quả yêu cầu được trả về thông qua bộ chặn theo chiều ngược lại. Kết quả trả về cho phép chúng ta thực hiện thu dọn hoặc thêm quá trình xử lý Hiển thị kết quả cho người sử dụng: việc điều khiển cuối cùng được trả về cho trình chứa servlet, nó sẽ gửi kết quả trả về cho trình duyệt của người sử dụng Hình 2: Tổng quan xử lý request trong Struts 2 Hình 3: Xử lý request trong Struts 2 Cấu hình Struts 2 trên Netbeans Cấu hình struts 2 project Một project của Struts 2 trên netbeans IDE cũng như bao project Web khác trên Netbeans nhưng có thêm một số phần quan trọng để cấu hình cũng như là thư viện để struts 2 hoạt động. Để cấu hình cho struts hoat động thì đầu tiên phải tạo một project bình thường và server của struts 2 chính là Tomcat và framework thì ta không chọn. Sau đó download thư viện struts 2 về. Bước tiếp theo thực hiện giải nén file thư viện struts ra một nơi nào đó trên ổ cứng. Và thực hiện add thư viện vào project của mình. Đối với một project Struts 2 đơn giản ta chỉ cần add các file .jar sau : commons-logging-1.0.4.jar, ognl-2.6.11.jar, xwork-2.0.4.jar, freemarker-2.3.8.jar, struts2-core-2.0.11.jar là đủ khi cần ta có thể add thêm các thư viện khác. Ta đã xong phần add thư viện cho project struts 2. Bước tiếp ta thực hiện tạo các file cấu hình là struts.xml trong package source, và chỉnh lại file cấu hình web.xml và thêm file applicationContext.xml trong package WEB-INF Để struts 2 hoạt động thì bạn phải viết lại file web.xml như sau: struts2 org.apache.struts2.dispatcher.FilterDispatcher struts2 /* 30 index.jsp Tiếp đến là file Struts.xml <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" ""> Và nội dung file applicationContext.xml sẽ là: Khai báo Struts 2 Có 2 cách để thực hiện khai báo cho struts2 là dùng xml để khai báo và dùng Annotation để khai báo. Sau đây là 2 cách khai báo đó trên môi trường của Netbeans Hình 4 Khai báo struts 2 Khai báo dùng xml Để hiểu hơn về cách cấu hình này thì chúng ta sẽ xem qua ví dụ sau: /AccountPage.jsp /Login.jsp /Registration.jsp /RegistrationSuccess.jsp /Registration.jsp Action Trong cách khai báo trên thì ứng với mỗi action ta sẽ khai báo trong thẻ “action” trong thẻ action thì có các thuộc tính như Name: là tên của action mà ta sẽ gọi Class : là ActionClass thực hiện xử lý action trên Method: nếu người dùng không khai báo attribute method này thì đồng nghĩa với việc Struts sẽ chọn phương thức execute trong ActionClass mà thực hiện. Còn nếu người dùng khai báo chổ này thì Struts sẽ lấy phương thức được khai báo để thực hiện sử lý cho action đó. Ngoài method như trên còn có một dạng gọi là WildCard method. Đôi khi ta thao tác trên một đối tượng có một tập các action ví dụ như SinhVien có các action mà người dùng thường sử dụng như là delete, insert , update, … thì ta có một cách đơn giản để khai báo mapping cho action là dùng wildcard method. Cách khai báo …. …. Cách sử dụng: … … Với delete là một phương thức trong ClassAction. Thỉnh thoảng thì chúng ta khai báo một action nhưng action đó không tồn tại nên struts sẽ báo lỗi, Chúng ta không muốn đều này xảy ra vì thế mà struts cung cấp thêm cho chúng ta cách config một action gọi là Default action để khi struts thực hiện mapping mà không tìm thấy action nào phù hợp nó sẽ thực hiện action default này. /UnderConstruction.jsp Result Trong thẻ action còn có thẻ con là result. Khi 1 Action được thực hiện thành công, nó sẽ trả về 1 chuỗi. Giá trị của chuỗi được sử dụng để chọn thành phần kết quả 1 action mapping sẽ thường có 1 tập thể hiện các kết quả khác nhau có thể xảy ra. Có các tên kết quả đã được xác định trước(tokens) Ứng dụng có thể định nghĩa các tên kết quả khác(token) để khớp với 1 số trường hợp mong muốn. Result định nghĩa trước gồm: String SUCCESS = "success"; String NONE = "none"; String ERROR = "error"; String INPUT = "input"; String LOGIN = "login"; Result Element: Name: tên result là giá trị trả về khi action thực hiện , nó có thể là tokens có sẳn hoặc là một tokens do mình định nghĩa. Type :kiểu result quy định kiểu result : depatcher, chain….. Nếu người dùng không khai báo thì struts sẽ lấy mặt định là depatcher. Có 3 cách để khai báo result: Khai báo không dùng type là default /ThankYou.jsp Khai báo sử dụng type defaults /ThankYou.jsp Khai báo sử dụng type default, param cũng default /ThankYou.jsp Khai báo dùng Annotation Đối với cách khai báo dùng Annotations thì ta sẽ xem xét ví dụ sau @Results({ @Result(name="input", value="/RegistrationSuccess.jsp" ) @Result(value="/RegistrationSuccess.jsp" ) }) public class Login implements Action { public String execute() { //Business logic for login } } Đây là cách khai báo trong lúc cài đặt ActionClass. Trong 2 cách trên người ta thường dùng nhất là cách dùng XML để cấu hình. Có một số người thì quen sử dụng các công nghệ cũ chỉ thực hiện cấu hình trên XML thì sẽ nhanh chóng tiếp cận hơn là cách dùng Annotation. Actions và Results Actions Khi một request được gởi từ phía người dùng đến server thì nó sẽ được ánh xạ thành một action tương ứng (do mình cấu hình). Và action này sẽ được controller điều hướng cho một classAction tương ứng thực thi (do chúng ta cấu hình). ActionClass : Nó là đơn vị làm việc cơ bản. Nó là một POJO mà có thêm phương thức execute(). Thường thì ActionClass được kế thừa từ lớp ActionSupport. ActionSupport: nằm trong package: com.opensymphony.xwork2. ActionSupport nó được implement từ lớp Action, LocaleProvider, TextProvider, Validateable, ValidationAware . Nó có một số thuộc tính final kế thừa từ lớp Action và được xem như là kết quả trả về từ action : ERROR, INPUT, LOGIN, NONE, SUCCESS. Có phương thức chủ yếu là execute() ,và một số phương thức tham khảo tại nguồn. Results Không giống như Struts1 kết quả của một action là một ActionForward. Trong Struts2 khi một phương thức thực thi một action hoàn thành thì kết quả nó trả về là một chuỗi và tùy vào chuỗi này mà ta có thể cấu hình để struts mapping với một tập các thể hiện của kết quả trả về cho người dùng Các loại results struts hỗ trợ sẵn Depatcher Result. Redirect Action Result Chain Result Redirect Result FreeMaker Result Velocity Result Plain Text Result Tiles Result HttpHeader Result Stream Result Global Result Depatcher Result Thực hiện include hoặc là forward đến một view thường là một trang jsp. Nếu trong quá trình khai báo mà ta không khai báo loại result thì mặc định Struts sẽ hiểu result theo kiểu Depatcher VD: foo.jsp Redirect Action Result Kết quả trả sau khi thực hiện action sẽ sử dụng ActionMapper để redirect để thực hiện một action khác Tham số: actionName : là tên action sẽ redirect tới namespace: là namespace chứa actionName. Nếu namespace là null thì Struts xem actionName nằm trong cùng namespace với action gọi nó. VD: dashboard /secure dashboard.jsp error error.jsp Chain Result Result này sẽ call đến toàn một action khác với toàn bộ interceptor stack và result của chính bản thân nó. Cách khai báo hoàn toàn giống với redirect action result chỉ thay chổ type là chain. Tham số: actionName: là action sẽ chuyển hướng đến namespace: là namespace chứa actionName, nếu là null thì là trong cùng namespace với action hiện tại method: là phương thức sẽ được gọi ở class Action của action đích. Nếu không khai báo thì sử dụng phương thức execute. skipAction: danh sách các action cách nhau bởi dấu “,” là những action có thể được chuyển hướng đến VD: /success.jsp error error.jsp Redirect Result Result này sẽ thực hiện redirect browser tới một vị trí/ trang khác . tương tự như HttpServletSponse.sendRedirect(url). Tham số location : là vị trí cần redirect tới VD: foo.jsp false FreeMaker Result Sẽ render một view sữ dụng template FreeMaker Tham số Location : nơi lưu template contentType: loại nội dung. Mặc định là “text/html” writeIfCompleted – (mặc định là false), write vào stream khi và chỉ khi không có lỗi nào trong quá trình xử lý mẫu. Cài đặt template_exception_handler=rethrow trong freemarker.properties sẽ có hiệu quả tương tự. VD: foo.ftl Velocity Result Giả lập một môi trường thực thi jsp và hiển thị theo mẫu Velocity Tham số: location : là vị trí mẫu để thực hiện xử lý VD: foo.vm Plain Text Result Result này thực hiện trả về nội dung theo định dạng text bình thường. Thường được sử dụng khi muốn thể hiện một trang web dưới dạng text bình thường. Tham số: Location : vị trí file cần show nội dung charSet: tập ký tự được sữ dụng VD: /myJspFile.jsp UTF-8 Tiles Result Đây là một plugin trong struts, tạo thuận tiện cho việc tái sữ dụng mã html HttpHeader Result Là một custom Result cài đặt trang thái và header của HTTP bằng cách tùy chọn giá trị của valueStack. Thường được dùng để thông báo lỗi cho người dùng. Tham số status - http servlet trả về mã trạng thái mà sẽ được thiết lập trên một response. headers – giá trị header. error - http servlet trả về mã lỗi mà sẽ được thiết lập trên một response. errorMessage – thông điệp lỗi để thiết lập trên response nếu tham số 'error' được thiết lập. VD: 204 a custom header value another custom header value 305 this action must be accessed through a prozy Stream Result Một loại Result tùy chọn để gửi dữ liệu thô (thông qua InputStream) trực tiếp đến HttpResponse. Rất hữu ích cho phép người sử dụng tải nội dung. Tham số contentType – mặc định là text/plain. contentLength – độ dài bytes. contentDispostion – giá trị các bố trí nội dung header để chỉ ra tên file (mặc định = inline, các giá trị đặc trưng filename="document.pdf". inputName – tên của thuộc tính InputStream từ action chuyển đến (mặc định = inputStream). bufferSize – kích thước của bộ đệm để copy từ input vào output (mặc định = 1024). VD: image/jpeg imageStream filename="document.pdf" 1024 XSL Result XSL Result sử dụng XSLT để chuyển một đối tượng action sang XML. Những phiên bản mới đây đã được thay đổi đặc tả để thỏa mãn với các luật Xalan. Tham số location (default) – nơi đến sau khi thực thi. matchingPattern – mẫu chỉ kết hợp với các phần tử mong muốn, mặc định nó kết hợp với mọi thứ. excludingPattern – mẫu loại bỏ các phần tử không mong muốn, mặc định không có gì. Global Result Loại kết quả này thường được dùng khi kết quả này được gán cho nhiều action khác nhau thì nếu ta khai báo trong mỗi action thì trở thành dư thừa do đó ta khai báo một lần và khi action thực hiện nếu trả ra đúng với một token nào đó thì result này sẽ được gọi VD: /Error.jsp Lúc này khi bất kì action nào trả về chuỗi error thì sẽ thực hiện depatcher tới Error.jsp Custom Result: Ngoài các Result trên thì developper có thể tự tạo cho mình một Result. Để custom một Result thì tạo một class và nó implement từ interface com.opensymphony.xwork2.Result có phương thức exectue. Giới Thiệu Interceptors Interceptor là một phần rất quan trọng trong Struts2 nó được cấu hình để thực hiện các chức năng như workflow, validation, upload file,… Khi được config thì khi một action triệu gọi nó sẽ qua các bộ interceptor nếu không bị interceptor điều hướng thì nó sẽ thực hiện action được gọi sau đó sẽ trả về kq và qua interceptor một lần nữa nhưng theo chiều ngược lại sau đó trà kết quả về cho người dùng. Hình 5 : Interceptor trong Action Life Circle Danh sách các Interceptor dựng sẵn Interceptor Name Alias Interceptor alias Chaining Interceptor chain Checkbox Interceptor checkbox Cookie Interceptor cookie Conversion Error Interceptor conversionError Create Session Interceptor createSession Debugging Interceptor debugging Execute And Wait Interceptor execAndWait Exception Interceptor exception File Upload Interceptor fileUpload I18N Interceptor i1n8 Logger Interceptor logger Message Store Interceptor store Model Driven Interceptor modelDriven Scoped Model Driven Interceptor scopedModelDriven Parameters Interceptor params Prepare Interceptor prepare Scope Interceptor scope Static Parameters Interceptor staticParams Roles Interceptor role Timer Interceptor timer Token Interceptor token Token Session Interceptor tokenSession Validation Interceptor validation WorkFlow Interceptor workflow Parameter Filter Interceptor N/A Profiling Interceptor profiling Custom một Interceptor Ngoài những interceptor trên thì ta cũng có thể tạo ra những interceptor cho chính chúng ta. Trong xwork cung cấp cho chúng ta một Interface Interceptor. Interface này có 3 phương thức chính là: init(): Phương thức được gọi đúng một lần sau khi Interceptor được tạo ra. intercept(): phương thức được gọi mỗi khi action được invoke và Intercept này sẽ thực hiện trước và sau khi action execute. destroy: phương thức gọi khi interceptor bị hủy . Thực hiện giải phóng tài nguyên. Trong xwork cũng cung cấp cho chúng ta một class abstract AbstractInterceptor lớp này implement từ Interface Interceptor. Nó cung cấp cho chúng ta 2 phương thức init() và destroy() rỗng. Tạo interceptor Để tạo một Interceptor thì ta thực hiện tạo một class và cho extends từ class AbstractInterceptor hay implement từ interface Interceptor. Sau đó thực hiện viết lại các phương thức cho phù hợp với muc đích của mình. VD: import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.interceptor.AbstractInterceptor; public class SimpleInterceptor extends AbstractInterceptor { public String intercept(ActionInvocation invocation) throws Exception{ MyAction action = (MyAction)invocation.getAction(); action.setDate(new Date()); return invocation.invoke(); } } Trong khi tạo một Interceptor chúng ta làm việc với 1 interface khá là quan trong là ActionInvocation. Inteface này nó đại diện cho trạng thực thi của một Action. Trong interface này có phương thức quan trọng là phương thức invoke(). Phương thức này để triệu gọi đến bước kế tiếp trong chuỗi xử lý một action Sử dụng custom interceptor: Strong struts.xml ta thực hiện khai báo interceptor của mình như sau: … login.jsp /secure/home … Có những lúc chúng ta muốn các interceptor của chúng ta thực hiện theo một thức tự và sữ dụng nhiều lần cùng một thứ tự đó thì nếu dùng cách khai báo từng interceptor trong mỗi action thì sẽ dư thừa. Do đó trong struts2 có khái niểm stack để chúng ta khai báo thứ tự của các interceptor mình sẽ dùng. Để hiểu rõ thì xem ví dụ sau: login.jsp /secure/home Các Tags trong struts 2 Tag library gồm: User Interface (UI) tags và non-UI tags , AJAX FORM TAGS Using Struts Tags Muốn sử dụng Tag Lib cần khai báo dòng sau vào đầu trang JSP Common Attributes The Common attributes Name Data Type Description cssClass String CSS class cssStyle String CSS style title String Thuộc tính tiêu đề Disabled String Thuộc tính vô hiệu hóa Label* String Nhãn labelPosition* String Vị trí của label Key String Tên của thuộc tính Requiredposition * String name String Thuộc tính name required Boolean tabIndex String Thuộc tính tabindex value String Giá trị Template-related attributes Name Data Type Description templateDir String Thư mục chứa template đang sử dụng theme String Tên của theme template String Tên của template Javascript-related attributes Name Data Type Description onclick String Sự kiện onclick ondblclick String Sự kiện ondblclick onmousedown String Sự kiện onmousedown onmouseup String Sự kiện onmouseup onmouseover String Sự kiện onmouseover onmouseout String Sự kiện onmouseout onfocus String Sự kiện onfocus onblur String Sự kiện onblur onkeypress String Sự kiện onkeypress onkeyup String Sự kiện onkeyup onkeydown String Sự kiện onkeydown onselect String Sự kiện onselect onchange String Sự kiện onchange Tooltip-related attributes Name Data Type Description tooltip String Nội dung tooltip. tooltipIconPath String Đường dẫn của ảnh làm tooltip. Mặc định /struts/static/tooltip/tooltip.gif tooltipDelay String Thời gian chờ (milliseconds) The Form Tag form tag attributes Name Data Type Default Value Description acceptcharset String Cho phép dấu Action String current action Action mà form sẽ gọi tên enctype String Thuộc tính anctype của form Method String Post Method namespace current namespace The namespace of the action onsubmit String Thuộc tính onsubmit openTemplate String Template được dùng portletMode String The portlet mode to display after the form submit Target String Thuộc tính target của form validate Boolean false Xác nhận hợp lệ windowState String Trạng thái của cửa sổ sau khi form được submit Ex: The textfield, password, hidden Tags The textfield, password, hidden Tags Name Data Type Default Value Description maxlength integer Số lượng kí tự tối đa readonly boolean false Thuộc tính xác định chỉ đọc size integer Kích thước The submit Tag Tag submit sẽ biến thành 1 nút. Có 3 loại: • input. Trả về submit as • button. Trả về submit as • image. Trả về submit as The submit Tag Name Data Type Default Value Description action String Thuộc tính action align String Thuộc tính canh lề method String Thuộc tính method type String input Loại button The reset Tag The reset tag trả về nút reset. Có 2 loại: • input. Trả về nút reset dạng • button. Trả về nút reset dạng The reset Tag Name Data Type Default Value Description action String Thuộc tính action align String Thuộc tính align method String Thuộc tính method type String input Loại button Ex: The label Tag The label Tag Name Data Type Default Value Description for String Thuộc tính for The head tag The head tag sẽ trả về tag head trong html. Ít được sử dụng. tuy nhiên rất quan trọng trong lập trình AJAX với Struts. The texterea tag The textarea Tag Name Data Type Default Value Description cols integer Thuộc tính cols readonly boolean false Thuộc tình xác định chỉ cho đọc rows integer Thuộc tính rows wrap boolean Thuộc tính wrap The checkbox Tag The checkbox Tag Name Data Type Default Value Description fieldValue String true Giá trị cùa checkbox. The list, listKey, and listValue attributes Ex: Tương đương : Atlanta Chicago Detroit The radio Tag The radio Tag Name Data Type Default Value Description list String Mảng listKey String Mảng khóa listValue String Mảng giá trị Ex: The select Tag The select Tag Name Data Type Default Value Description emptyOption boolean false Indicates whether or not to insert an empty option after the header. headerKey String Giá trị đầu tiên của khóa headerValue String Giá trị đầu tiên của value list String Danh sách listKey String Danh sách khóa listValue String Danh sách giá trị multiple boolean false Cho phép chọn nhiều lựa chọn hay không size integer Số lựa chọn được hiển thị Ex: <s:select name="city" label="City" headerKey="0" headerValue="[Select a city]" list="#{'1':'Atlanta', '2':'Chicago', '3':'Detroit'}" /> Select Option Grouping with optgroup Select Option Grouping with optgroup Name Data Type Default Value Description list String Danh sách listKey String Danh sách khóa listValue String Danh sách giá trị Select Option Grouping with optgroup Select Option Grouping with optgroup Name Data Type Default Value Description list String Danh sách listKey String Danh sách khóa listValue String Danh sách giá trị The combobox Tag The combobox Tag Name DataType Default Value Description emptyOption boolean false Indicates if an empty option should be inserted. headerKey integer The key for headerValue, should be -1. headerValue String Text that will be added as a select option but is not intended to be selected list String Danh sách listKey String Danh sách khóa listValue String Danh sách giá trị maxlength integer Độ dài tối đa readonly boolean false Xác định chỉ cho phép xem size integer Kích thước The updownselect Tag The updownselect Tag Name DataType Default Value Description allowMoveDown Boolean True Hiển thị button xuống allowMoveUp Boolean True Hiển thị button lên allowSelectAll Boolean True Cho phép chọn tất cả emptyOption boolean False Indicates whether an empty (--) option should be inserted after the header option. headerKey integer The key for headerValue, should be -1. headerValue String Text that will be added as a select option but is not intended to be selected list String Danh sách listKey String Danh sách khóa listValue String Danh sách giá trị moveDownLabel String V Text hiển thị lên nút lên moveUpLabel String ^ Text hiển thị xuống dưới multiple boolean false Cho phép chọn nhiều lựa chọn hay không? selectAllLabel String Text to display on the select all button. size Integer Số lựa chọn được hiển thị GENERIC TAGS The property Tag The property Tag Name Data Type Default Value Description default String Giá trị mặt định nếu giá trị của nó là rỗng escape boolean true Whether HTML special characters are escaped value String Giá trị để hiển thị Ex: The a Tag Sẽ cho ra 1 link trong html Ex: Click Here The action Tag The property Tag Name Data Type DefaultValue Description executeResult boolean false Indicates whether the action result should be executed/rendered. flush boolean true Indicates whether the writer should be flushed at the end of the action component tag. ignoreContextParams boolean false Whether request parameters are to be included when the action is invoked. name String The name of the action to be invoked, without the .action suffix. namespace String The namespace from where the tag is used The namespace of the action to be invoked. var String The name to be used to reference the action added to the context map. Ex: The param Tag The property Tag Name DataType Default Value Description Name String The name of the parameter to be passed to the containing tag. Value String The value of the parameter to be passed to the containing tag. Ex: The bean Tag The bean Tag Name DataType Default Value Description Name String The fully qualified class name of the JavaBean to be created. Var String The name used to reference the value pushed into the Value Stack's context map. Ex: The date Tag The date Tag Name DataType Default Value Description format String Format date name String Giá trị Nice boolean Whether to apply nice formatting. Var String The name used to reference the value pushed to the value stack. Ex: The include Tag The include Tag Name DataType Default Value Description value String File được chọn để include The set Tag The set Tag Name DataType Default Value Description name String The key of the attribute to be created value String The object to be referenced by the key. scope String default The scope of the target variable. The value can be application, session, request, page, or default. Ex: The push Tag The push Tag Name Data Type Default Value Description value String Giá trị Ex: Employee Id: First Name: Last Name: The url Tag The push Tag Name DataType Default Value Description action String The action that the created URL will target. anchor String The anchor for the created URL encode Boolean true Whether to encode parameters. escapeAmp Boolean true Indicates whether to escape the ampersand character (&) includeContext Boolean true Indicates whether the actual context should be included includeParams String get One of these values: one, get, all. method String The method of the action. namespace String The target namespace. portletMode String The resulting portlet mode. portletlUrlType String Indicates if the created URL should be a portlet render or an action URL. scheme String The scheme ??? value String The target value to use, if not using action var String ??? windowState String When used in a portlet environment, specifies the portlet window state. Ex: <s:url id="siteUrl" forceAddSchemeHostAndPort="true" value="" includeparams="none" scheme="https"/> The if, else, and elseIf Tags The if, else, and elseIf Tags Name DataType Default Value Description test Boolean Điều kiện test Ex: The iterator Tag iterator tag attributes Name Data Type Default Value Description value String The iterable object to iterate over. status org.apache.struts2.views.jsp. IteratorStatus var String The variable to reference the current element of the iterable object. IteratorStatus object attributes Name DataType Default Value Description index integer The zero-based index of each iteration count integer The current iteration or index + 1. first boolean The value is true if the current element is the first element in the iterable object. last boolean The value is true if the current element is the last element in the iterable object. even boolean The value is true if count is an even number odd boolean The value is true if count is an odd number modulus int This property takes an integer and returns the modulus of count. The append Tag The if, else, and elseIf Tags Name DataType Default Value Description var String The variable that will be created to reference the appended iterators. Ex: The merge Tag The if, else, and elseIf Tags Name DataType Default Value Description var String The variable that will be created to reference the appended iterators. The generator Tag The if, else, and elseIf Tags Name DataType Default Value Description converter Converter The converter to convert the String entry parsed from val into an object. count Integer The maximum number of elements in the iterator. separator String The separator for separating the val into entries of the iterator. val String The source to be parsed into an iterator. var String The variable that references the resulting iterator. Ex: The sort Tag The if, else, and elseIf Tags Name DataType Default Value Description comparator String The comparator that will be used in the sor ting. source String The iterable source to sort. var String The variable that will be created to reference the new iterator. The subset Tag The if, else, and elseIf Tags Name DataType Default Value Description count Integer The number of entries in the resulting iterator. decider Decider An implementation of the SubsetIteratorFilter.Decider interface that determines if an entry is to be included in the resulting subset. source String The source iterator to subset. start Integer The starting index of the source iterator to be included in the subset. var String The variable to be created to reference to the subset. Ajax và Struts 2 The Head Tag The Head Tag Name DataType Default Value Description baseRelativePath String /struts/dojo The path to the Dojo distribution folder cache boolean true Indicates if Dojo files should be cached by the browser. compressed boolean true Indicates whether or not the compressed version of Dojo files should be used. debug boolean false Indicates whether or not Dojo should be in debug mode. extraLocales String Comma delimited list of locales to be used by Dojo. locale String đường dẫn của Dojo. parseContent boolean false Indicates whether or not to parse the whole document for widgets. The Div Tag The Div Tag Name DataType Default Value Description afterNotifyTopics String Comma delimited topics to be published after the request, if the request is successful. autoStart boolean true Whether or not to start the timer automatically. beforeNotifyTopics String Comma delimited topics to be published before the request. closable boolean false Whether or not to show a Close button when the div is inside a tabbed panel delay integer The number of milliseconds that must elapse before the content is fetched errorNotifyTopics String Comma delimited topics to be published after the request, if the request fails. errorText String The text to be displayed if the request fails. executeScripts boolean false Indicates whether or not JavaScript code in the fetched content should be executed. formFilter String The function to be used to filter the form fields. formId String The identifier of the form whose fields will be passed as request parameters. handler String The JavaScript function that will make the request. highlightColor String The color to highlight the elements specified in the targets attribute. highlightDuration integer 2000 The duration in milliseconds the elements specified in the targets attribute will be highlighted. This attribute will only take effect if the hightlightColor attribute has a value. href String The URL to call to fetch the content. indicator String The identifier of the element that will be displayed while making the request. javascriptTooltip boolean false Indicates whether or not to use JavaScript to generate tooltips. listenTopics String The topics that will trigger the remote call. loadingText String The text to display while content is being fetched. notifyTopics String Comma delimited topics to be published before and after the request and upon an error occurring. openTemplate String The template to use for opening the rendered HTML parseContent boolean true Whether or not to parse the returned content for widgets. preload boolean true Whether or not to load content when the page is loaded. refreshOnShow boolean false Whether or not to load content when the div becomes visible. This attribute takes effect only if the div is inside a tabbed panel. separateScripts boolean true Whether or not to run the script in a separate scope that is unique for each tag showErrorTransportText boolean true Whether or not errors will be shown. showLoadingText boolean false Whether or not loading text will be shown on targets startTimerListenTopics String Topics that will start the timer stopTimerListenTopics String Topics that will stop the timer transport String XMLHttp Transport The transport for making the request updateFreq integer The frequency (in milliseconds) of content update The a Tag The a Tag Name DataType Default Value Description afterNotifyTopics String Comma delimited topics to be published after the request, if the request is successful. ajaxAfterValidation boolean false Indicates whether or not to make an asynchronous request if validation succeeds. This attribute will only take effect if the validate attribute is set to true beforeNotifyTopics String Comma delimited topics to be published before the request. errorNotifyTopics String Comma delimited topics to be published after the request, if the request fails. errorText String The text to be displayed if the request fails. executeScripts boolean false Indicates whether or not JavaScript code in the fetched content should be executed. formFilter String The function to be used to filter the form fields. formId String The identifier of the form whose fields will be passed as request parameters. handler String The JavaScript function that will make the request. highlightColor String The color to highlight the elements specified in the targets attribute. highlightDuration integer 2000 The duration in milliseconds the elements specified in the targets attribute will be highlighted. This attribute will only take effect if the hightlightColor attribute has a value. href String The URL to call to fetch the content indicator String The identifier of the element that will be displayed while making the request. javascriptTooltip boolean Indicates whether or not to use JavaScript to generate tooltips. listenTopics String The topics that will trigger the remote call loadingText String Loading... The text to display while content is being fetched notifyTopics String Comma delimited topics to be published before and after the request and upon an error occurring openTemplate String The template to use for opening the rendered HTML parseContent boolean true Whether or not to parse the returned content for widgets. separateScripts boolean true Whether or not to run the script in a separate scope that is unique for each tag. showErrorTransportText boolean true Whether or not errors will be shown. showLoadingText boolean false Whether or not loading text will be shown on targets targets String Comma delimited identifiers of the elements whose content will be updated transport String XMLHttp Transport The transport for making the request validate boolean false Whether or not AJAX validation should be performed The Submit Tag The a Tag Name DataType Default Value Description afterNotifyTopics String Comma delimited topics to be published after the request, if the request is successful. ajaxAfterValidation boolean false Indicates whether or not to make an asynchronous request if validation succeeds. This attribute will only take effect if the validate attribute is set to true. beforeNotifyTopics String Comma delimited topics to be published before the request. errorNotifyTopics String Comma delimited topics to be published after the request, if the request fails. errorText String The text to be displayed if the request fails. executeScripts boolean false Indicates whether or not JavaScript code in the fetched content should be executed. formFilter String The function to be used to filter the form fields. formId String The identifier of the form whose fields will be passed as request parameters. handler String The JavaScript function that will make the request. highlightColor String The color to highlight the elements specified in the targets attribute. highlightDuration integer 2000 The duration in milliseconds the elements specified in the targets attribute will be highlighted. This attribute will only take effect if the hightlightColor attribute has a value. href String The URL to call to fetch the content. indicator String The identifier of the element that will be displayed while making the request. javascriptTooltip boolean false Indicates whether or not to use JavaScript to generate tooltips. listenTopics String The topics that will trigger the remote call. loadingText String Loading... The text to display while content is being fetched. method String The method attribute. notifyTopics String Comma delimited topics to be published before and after the request and upon an error occurring. parseContent boolean true Whether or not to parse the returned content for widgets. separateScripts boolean True Whether or not to run the script in a separate scope that is unique for each tag. showErrorTransportText boolean true Whether or not errors will be shown showLoadingText boolean false Whether or not loading text will be shown on targets src String The image source for a submit button of type image. targets String Comma delimited identifiers of the elements whose content will be updated transport String XMLHttp Transport The transport for making the request type String input The type of the submit button. Possible values are input, image, and button. validate boolean false Whether or not AJAX validation should be performed The Bind Tag The Bind Tag Name DataType Default Value Description afterNotifyTopics String Comma delimited topics to be published after the request, if the request is successful. ajaxAfterValidation boolean false Indicates whether or not to make an asynchronous request if validation succeeds. This attribute will only take effect if the validate attribute is set to true. beforeNotifyTopics String Comma delimited topics to be published before the request. errorNotifyTopics String Comma delimited topics to be published after the request, if the request fails. errorText String The text to be displayed if the request fails. events String Comma delimited event names to attach to executeScripts boolean false Indicates whether or not JavaScript code in the fetched content should be executed. formFilter String The function to be used to filter the form fields. formId String The identifier of the form whose fields will be passed as request parameters. handler String The JavaScript function that will make the request. highlightColor String The color to highlight the elements specified in the targets attribute. highlightDuration integer 2000 The duration in milliseconds the elements specified in the targets attribute will be highlighted. This attribute will only take effect if the hightlightColor attribute has a value. href String The URL to call to fetch the content. indicator String The identifier of the element that will be displayed while making the request. listenTopics String The topics that will trigger the remote call. loadingText String The text to display while content is being fetched. notifyTopics String Comma delimited topics to be published before and after the request and upon an error occurring. separateScripts boolean Whether or not to run the script in a separate scope that is unique for each tag. showErrorTransportText boolean true Whether or not errors will be shown. showLoadingText boolean false Whether or not loading text will be shown on targets sources String Comma delimited identifiers of the elements to attach to targets String Comma delimited identifiers of the elements whose content will be updated transport String XMLHttp Transport The transport for making the request validate boolean false Whether or not AJAX validation should be performed The datetimepicker Tag The datetimepicker Tag Name DataType Default Value Description adjustWeeks boolean false Whether or not to adjust the number of rows in each month. If this attribute value is false, there are always six rows in each month. dayWidth String narrow Determines the day names in the header. Possible values are narrow, abbr, and wide. displayFormat String The date and time pattern according to Unicode Technical Standard #35 displayWeeks integer 6 The number of weeks to display endDate Date 2941-10-12 The last available date formatLength String Short The formatting type for the display. Possible values are short, medium, long, and full. javascriptTooltip boolean false Indicates whether or not to use JavaScript to generate tooltips. language String The language to use. The default language is the browser's default language. startDate Date 1492-10-12 The first available date staticDisplay boolean false Whether or not only the dates in the current month can be viewed and selected toggleDuration integer 100 The toggle duration in milliseconds toggleType String plain The toggle type for the dropdown. Possible values are plain, wipe, explode, and fade. type String date Whether this widget will be rendered as a date picker or a time picker. Allowed values are date and time. valueNotifyTopics String Comma delimited topics that will be published when a value is selected. weekStartsOn integer 0 The first day of the week. 0 is Sunday and 6 is Saturday. The tabbedpanel Tag The datetimepicker Tag Name DataType Default Value Description afterNotifyTopics String Comma delimited topics to be published after the request, if the request is successful. ajaxAfterValidation boolean false Indicates whether or not to make an asynchronous request if validation succeeds. This attribute will only take effect if the validate attribute is set to true. beforeNotifyTopics String Comma delimited topics to be published before the request. errorNotifyTopics String Comma delimited topics to be published after the request, if the request fails. errorText String The text to be displayed if the request fails. executeScripts boolean false Indicates whether or not JavaScript code in the fetched content should be executed. formFilter String The function to be used to filter the form fields. formId String The identifier of the form whose fields will be passed as request parameters. handler String The JavaScript function that will make the request. highlightColor String The color to highlight the elements specified in the targets attribute. highlightDuration integer 2000 The duration in milliseconds the elements specified in the targets attribute will be highlighted. This attribute will only take effect if the hightlightColor attribute has a value href String The URL to call to fetch the content. indicator String The identifier of the element that will be displayed while making the request. javascriptTooltip boolean false Indicates whether or not to use JavaScript to generate tooltips. listenTopics String The topics that will trigger the remote call. loadingText String Loading... The text to display while content is being fetched. notifyTopics String Comma delimited topics to be published before and after the request and upon an error occurring. parseContent Boolean true Whether or not to parse the returned content for widgets. separateScripts Boolean true Whether or not to run the script in a separate scope that is unique for each tag. showErrorTransportText Boolean true Whether or not errors will be shown. showLoadingText boolean false Whether or not loading text will be shown on targets targets String Comma delimited identifiers of the elements whose content will be updated transport String XMLHttp Transport The transport for making the request validate boolean false Whether or not AJAX validation should be performed The textarea Tag The datetimepicker Tag Name DataType Default Value Description cols integer Số Cột rows integer Số dòng wrap boolean false Thuộc tính wrap The autocompleter Tag The autocompleter Tag Name DataType Default Value Description afterNotifyTopics String Comma delimited topics to be published after the request, if the request is successful. autoComplete beforeNotifyTopics string Comma delimited topics to be published before the request dataFieldName string value in the name attribute The name of the field in the returned JSON object that contains the data array delay Integer 100 The delay in milliseconds before making the search dropdownHeight Integer 120 The height of the dropdown in pixels dropdownWidth Integer the same as the textbox The width of the dropdown in pixels emptyOption boolean False Whether or not to insert an empty option errorNotifyTopics String Comma delimited topics to be published after the request, if the request fails. forceValidOption boolean False Whether or not only an included option can be selected formFilter String The function to be used to filter the form fields. formId String The identifier of the form whose fields will be passed as request parameters. headerKey String The key for the first item in the list headerValue String The value for the first item in the list href String The URL to call to fetch the content. iconPath String Path to the icon used for the dropdown indicator String The identifier of the element that will be displayed while making the request javascriptTooltip boolean false Indicates whether or not to use JavaScript to generate tooltips. keyName String The property to which the selected key will be assigned. list String An iterable source to populate from listKey String The property of the object in the list that will supply the option values listValue String The property of the object in the list that will supply the option labels listenTopics String The topics that will trigger the remote call. loadMinimumCount Integer 3 The minimum number of characters that must be entered to the textbox before options will be loaded loadOnTextChange boolean true Whether or not to reload options every time a character is entered to the texbox maxlength integer Corresponds to the HTML maxlength attribute notifyTopics String Comma delimited topics to be published before and after the request and upon an error occurring. preload boolean true Whether or not to reload options when the page loads resultsLimit integer 30 The maximum number of options. -1 indicates no limit. searchType String startstring Search type, possible values are startstring, startword, and substring. showDownArrow boolean true Whether or not to show the down arrow transport String XMLHttp Transport The transport for making the request valueNotifyTopics String Comma delimited topics that will be published when a value is selected The tree and treenode Tags tree tag attributes Name DataType Default Value Description blankIconSrc String The source for the blank icon childCollectionProperty String The name of the property that returns a collection of child nodes collapsedNotifyTopics String Comma separated topics to be published when a node is collapsed errorNotifyTopics String Comma delimited topics to be published after the request, if the request fails. expandIconSrcMinus String The source for the expand icon expandIconSrcPlus String The source for the expand icon expandedNotifyTopics String Comma delimited topics to be published when a node is expanded gridIconSrcC String Image source for under child item child icons gridIconSrcL String Image source for the last child grid gridIconSrcP String Image source for under parent item child icons gridIconSrcV String Image source for vertical line gridIconSrcX String Image source for grid for sole root item gridIconSrcY String Image source for grid for last root item href String The URL to call to fetch the content iconHeight String 18px The icon height iconWidth String 19px The icon width javascriptTooltip boolean false Indicates whether or not to use JavaScript to generate tooltips. nodeIdProperty The name of the property whose value is to be used as the node id nodeTitleProperty The name of the property whose value is to be used as the node title openTemplate String The template to use for opening the rendered HTML rootNode String The name of the property whose value is to be used as the root selectedNotifyTopics String Comma delimited topics to be published when a node is selected. An object with a property named node will be passed to the subscribers. showGrid Boolean true Whether or not to show the grid showRootGrid boolean True The showRootGrid property toggle String Fade The toggle property. Possible values are fade or explode. toggleDuration integer 50 Toggle duration in milliseconds treenode tag attributes Name DataType Default Value Description javascriptTooltip boolean false Tooltip openTemplate String Templates đang được sử dụng Tài liệu tham khảo Struts 2 Basic Struts 2 In Action (Donal Brown, Chad Michael Davis, Scott Stanlick). Struts 2 Design And Programming by Budi Kurniawan

Các file đính kèm theo tài liệu này:

  • docstrust2_2552.doc
Luận văn liên quan