Professional Documents
Culture Documents
Ori Dar
Consultant and Architect,
AlphaCSP
2
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Agenda
Introduction
Background
Framework features review
Configuration
View technology
Page flow
Form binding
Table sorting
Pagination
Validation
AJAX
Error handling
I18n support
Documentation
Summary
3
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Introduction::In a nutshell (1)
5
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Introduction::In a nutshell (3)
6
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Introduction::HelloWorld
Controller: FilterDispatcher
<filter>
<filter-name>action2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>action2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
web.xml
7
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Introduction::HelloWorld, Model
8
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Introduction::HelloWorld, View
View: HelloWorld.jsp
–Utilizes a single struts taglib
–The taglib is common for JSP, Velocity
and FreeMarker
Prints action’s
<%@ taglib prefix="s" uri="/struts-tags"%>
message property.
<html>
<body>
Unlike struts1,
<s:property value=“message“/> action is a POJO,
</body> and acts as a model
</html>
9
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Introduction::HelloWorld
struts.xml:
–Actions mapping links action to view
–Results mapping
<action name=“hello“ class="com.alphacsp.actions.HelloWorld">
<result name=“success“>/pages/HelloWorld.jsp</result>
</action>
10
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Agenda
Introduction
Background
Framework features review
Configuration
View technology
Page flow
Form binding
Table sorting
Pagination
Validation
AJAX
Error handling
I18n support
Documentation
Summary
11
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Background::S2 Vs. S1
Struts2 Struts1
POJO (with execute) Action Extends Action
Model Action Role Controller
Decoupled Servlet API Dependant
Instance per request Threading Single instance
Action JavaBean Form binding Action Form
properties
Value Stack View binding JSP mechanisms
OGNL EL JSTL EL
xml or annotations Validation Action Form
Independent via Lifecycle Shared
interceptors
Wildcards, annotations Configuration Verbose
12
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Background::Interceptors
13
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Background::Interceptors
<interceptor-stack name="basicStack">
<interceptor-ref name="exception"/> interceptor stack
<interceptor-ref name="servletConfig"/> contains other interceptors
<interceptor-ref name="prepare"/>
<interceptor-ref name="checkbox"/>
<interceptor-ref name="params"/>
<interceptor-ref name="conversionError"/>
</interceptor-stack> the default stack
</interceptors> for actions in package
<default-interceptor-ref name="defaultStack"/>
</package> struts-default.xml
14
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Background::ValueStack
15
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Background::OGNL
• Tag Library
– Form component tags
– Ajax UI component tags
– Control tags: iterator, if/else…
– Data tags: manipulate the ValueStack
• Datatype conversion framework
• Themes: templates for customizing
components markup
17
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Background:: Theme example
18
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Background::Other features
19
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Agenda
Introduction
Background
Framework features review
Configuration
View technology
Page flow
Form binding
Table sorting
Pagination
Validation
AJAX
Error handling
I18n support
Documentation
Summary
20
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Features::Action Configuration
result name
result type
action method should return
the view technology
a matching result code string
(default value: “dispatcher”
(default value: “success”)
for rendering JSP)
21
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Features:: Action Configuration
22
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Features::Annotation Config.
• Result types
– JSP : dispatcher
– Velocity
– FreeMarker
– XSLT
– Stream : PDF, MS Word etc.
• Plugins
– JasperReports
– JFreeChart
– JSON
24
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Features::Page flow
2
4
3
5
25
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Features::Page flow
27
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Features::Table sorting
29
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Features::Pagination
30
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Features::Validation
31
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Features::Validation
<validators>
@EmailValidator(
<field name="email">
fieldName = "email",
<field-validator type="email">
key="wrongEmailFormat",
<message key="wrongEmailFormat">
message="Wrong Email Format")
Wrong Email Format
</message>
public void setEmail(String email) {
</field-validator>
this.email = email;
</field>
}
</validators>
PhoneBook.java PhoneBook_validation.xml
32
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Features::Client side validation
33
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Features::Ajax
34
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Features::Ajax autocompleter
View
<s:url id="acUrl" action="getDepts"/>
<s:autocompleter name="dept" href="%{acUrl}" cssClass="acSearchField"/>
phoneBook.jsp
Action
privateList<String> ;deptList
action name=""getDepts>
public String execute() {
<class=""DeptsAutoComplete
deptList = service.findAllDepartments();
<result type=""json>
return ActionSupport.SUCCESS;
<param name="root">deptList</param>
}
<result/>
<action/>
public List<String> getDeptList() {
return deptList;
} PhoneBook.java struts-default.xml
35
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Features::Error handling
36
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Features::Error handling
•Exception interceptor
–maps exceptions to result error pages
–should be first in interceptor stack
<global-exception-mappings>
<exception-mapping exception="java.lang.Exception" result="sysError"/>
</global-exception-mappings>
struts.xml
37
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Features::I18N support
38
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Features::Documentation
39
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Agenda
Introduction
Background
Framework features review
Configuration
View technology
Page flow
Form binding
Table sorting
Pagination
Validation
AJAX
Error handling
I18n support
Documentation
Summary
40
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Summary::Pros
41
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Summary::Pros
42
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Summary::Cons
Unorganized documentation
Lack of API documentation
No clear roadmap
ActionSupport dependency
Lack of @Action
Lack of @Interceptor
Cases when fallback to Servlet API is
needed
Weakly typed sessions
43
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Summary::When to use
• Use when
– Migrating from legacy framework
– Natural around HTTP request response
paradigm
– Suitable for streaming
– POC, prototype, RAD
• Don’t use when
– Heavily utilized RIA is needed
– Your developers have Swing orientation
44
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar
Thank
You !
45
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar