migrating to apache wicket - wordpress.com...url mapping xml java action handler / controller...
TRANSCRIPT
![Page 1: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/1.jpg)
Migrating to Apache Wicket
Peter Thomas
Satyam Computer Services Ltd.
![Page 2: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/2.jpg)
Prelude
• Introduction
• Expectations
• Workshop (later today)
– “Wicket, Spring & Hibernate”
– Code, Demos
– Hall B
– 2:40 PM
2
![Page 3: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/3.jpg)
Session Outline
• Subject Application
• Wicket Overview
• Architecture (before)
• Migration
• Architecture (after)
• Comparison / Benefits
• Parting Thoughts
• Q & A
3
![Page 4: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/4.jpg)
The Subject Application
• Open Source issue-management
• SourceForge Project: http://jtrac.info
• 40,000 downloads till date
• Localized into 15 languages
• FOSS India Award Winner 2008
4
![Page 5: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/5.jpg)
Wicket Highlights
• Web application framework
• Component based & Object Oriented
• Just Java & HTML
• Clean separation of Code and Markup
• Easy to create and re-use custom components
• Transparent state & session management
• Built-in AJAX without needing to write Javascript
• No XML config
5
![Page 6: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/6.jpg)
Wicket - History
• 2004: project started
• 2005: version 1.0
• 2006: version 1.2
• 2007
– graduates from Apache incubator
– becomes top-level Apache project
• 2008: Currently at version 1.3.3
6
http://wicket.apache.org
![Page 7: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/7.jpg)
Hello World!
7
![Page 8: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/8.jpg)
Initial Architecture
8
Presentation
Service
Persistence
Database
Hibernate 3
Spring DAO / Hibernate Support
Spring TX
Spring
Security
(Acegi)
Spring AOP
Spring
Context(DI / IoC
container)
POJO POJO POJO
Spring WebFlow
Spring MVC
JSP / JSTL
![Page 9: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/9.jpg)
Dashboard AJAX ‘drill-down’ example
9
![Page 10: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/10.jpg)
Controller Code
• Just returns a Model with 2 objects
– a collection loaded from the database
– session user
• All the action is in “dashboard.jsp” …
10
![Page 11: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/11.jpg)
Typical JSP / Action MVC flow
11
Map URL to
Action
Prepare Model,
push to JSP
Render View
using Model
data
Request
Response
Framework
configuration
Java code in
Controller / Action
JSP
Not much to do
here for read-
only views, just
get data from
the DAO
What about
here?
![Page 12: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/12.jpg)
12
JSP include for
common header)
JavaScript for AJAX
wired to <A> „onClick‟
Replace HTML dom
element (Prototype)
JSTL iterate
Hacking HTML DOM
„id‟ for AJAX
Ajax response
handler
JSP-EL + MVC
URL (another
JSP & controller)
JSTL conditional logic
Show AJAX „busy‟ indicator
![Page 13: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/13.jpg)
Wicket version - Java
13
DashboardPage.java
DashboardRowPanel.java
Iterate using Wicket
repeater component
Chunk of HTML modeled as
a re-usable Java component
share data across
components using
normal Java and OO
Wicket generates
HTML id for you
Replace self with another
component over AJAX
Special Link component
shows AJAX „busy‟
indicator automatically
onClick event handler,
(in this case for AJAX)
![Page 14: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/14.jpg)
Wicket version – HTML panel
14
![Page 15: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/15.jpg)
The JSP / Action MVC ‘full stack’
15
HTML / CSS
Prototype / JS
JSP / JSP-EL
JSTL
TagLibs / Scriptlets
Markup
AJAX /
DOM Scripting
Templating
Logic / Iteration
Additional Logic
Tiles / SitemeshPage Layout /
Composition
XMLURL mapping
JavaAction Handler
/ Controller
Acegi / Spring Sec.Security
WebFlowPage Flow /
Navigation
HTML / CSSMarkup
JavaComponents
![Page 16: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/16.jpg)
Common header / footer in JSP
• have to remember to „include‟ for all pages
• or use something like Tiles / Sitemesh
16
![Page 17: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/17.jpg)
Markup Inheritance
17
![Page 18: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/18.jpg)
Wicket compared to JSP
• True separation of concerns
• „Preview-ability‟ in a browser or HTML editor
• Absolutely no logic or code in the markup
• Work in pure Java and not in EL / JSTL / taglibs
• IDE support for Java
– Syntax highlighting, autocomplete
– Refactor safely and freely
– Debug and step through your code with ease
• Markup inheritance for common header / footer etc.
• Panels: Composition and reuse
• OO and not procedural „request-response‟ controller code
• XHTML compliant by default18
![Page 19: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/19.jpg)
Side note: Wicket & Jetty
• Not really a big deal but
• Nice if you want to embed a web-app-server
• No more JSPC
• Makes you see all those app-servers in a new light ;)19
Jetty footprint with JSP support without JSP support
![Page 20: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/20.jpg)
Wicket in development mode
• Detailed error reporting
• Refresh changes to markup on the fly
• AJAX debug window
20
![Page 21: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/21.jpg)
Wicket Components
21
© Stefan Kanev
http://spider.bg/~aquarius/dl/Wicket%20Components%200.1.png
![Page 22: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/22.jpg)
Custom Components
• extend (yes, the Java keyword ;)
• or group existing ones into Panels
22
![Page 23: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/23.jpg)
What about page-flow / navigation?
23
userForm
userList
View
cancel
submit userForm
Handler
Space ==
null ?
yes
no
choose
Space
cancel / done
allocate
handler
submit
user
Allocate
Flow
call
sub-flow
return to
calling flow
![Page 24: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/24.jpg)
Spring WebFlow 1.0 flow definition
24
Logical
View Name
(finally JSP)
State
Transitions
backend logic
invocation
(Java method)
Flow Decision Logic
Re-usable
Flow invocation
Input / output
variables & ‘scope’
![Page 25: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/25.jpg)
Wicket - returning to ‘caller’ page e.g.
25
UserListPage: navigate to UserFormPage after setting self as ‘caller’
UserFormPage: ‘cancel’ returns to previous page (or OptionsPage if no previous page)
a WebPage instance
is just a normal Java
object :)
![Page 26: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/26.jpg)
Page-Flow vs Partial-Update
26
![Page 27: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/27.jpg)
Forms: when *you* manage state…
27
Hidden Form Fields
Controller code to load form backing object
You may even need code to bind drop-downs / multi-selects to domain
objects (or collections of them)
![Page 28: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/28.jpg)
Wicket Forms: POJO binding
28
WebPage
Form
TextField
TextField
“name”
“description”
Model
bind to inherited model,
re-use identifier as
property expression
![Page 29: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/29.jpg)
Wicket Forms: some highlights
• File-Upload supported out of the box
• Easy to have multiple submit buttons on a form
• Redirect after POST by default
• Nested forms are possible
• Unlimited possibilities for feedback / validation
messages
– e.g. using Ajax
29
![Page 30: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/30.jpg)
Wicket Form Validators
• Wide variety of built-in validators
• Easy to implement your own
30
![Page 31: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/31.jpg)
Form Validation Feedback example
31
Component based
manipulation of
markup: red CSS
border around fields
with errors
![Page 32: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/32.jpg)
Wicket ‘Behavior’s
• Ready-made behaviors for common needs
• e.g. color alternate rows of an HTML table
32
![Page 33: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/33.jpg)
JFreeChart Example
33
Spring MVC
URL mapping
Dynamic Image
Resource
Wicket Image
writing to raw
HTTP response
in controller
![Page 34: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/34.jpg)
YUI Integration (custom created)
34
Yahoo! UI date
pickernon-modal, resizable
Javascript pop-up window
using Yahoo! UI
(lazy-loads over Ajax)
![Page 35: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/35.jpg)
Other Wicket features worth noting
• Secure URLs by default
• Support for REST-ful or „friendly‟ URLs
• Subclass and use custom (type-safe) session
• Transparent browser back-button support
• Comprehensive i18n
• Easy integration with Spring
• WicketTester: UI component unit-testing support
35
![Page 36: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/36.jpg)
Final Architecture
36
Presentation
Business
Data Access
Database
Hibernate 3
Spring – Hibernate - DAO
Spring TX
Spring
Security
(Acegi)Spring AOP
Apache Wicket
Spring
Context(DI / IoC
container)
POJO POJO POJO
![Page 37: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/37.jpg)
Parting thoughts
• Surprisingly many Java web-frameworks move
developers towards non-Java, non-OO work
• Most development time is spent on the UI
• DSL based / declarative approaches have limits
• Java == power and expressiveness
37
![Page 38: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/38.jpg)
Thank You
38
![Page 39: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/39.jpg)
Wicket IDE Support
• Eclipse Plugin
– Wicket Bench
– http://www.laughingpanda.org/mediawiki/inde
x.php/Wicket_Bench
• NetBeans Module
– Wicket 1.3.3 Support
– http://plugins.netbeans.org/PluginPortal/faces
/PluginDetailPage.jsp?pluginid=3586
39
![Page 40: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/40.jpg)
Books• Wicket in Action
– Martijn Dashorst, Eelco Hillenius
– http://manning.com/dashorst
– http://www.amazon.com/exec/obidos/tg/detail/-/1932394982/apachesoftwar-20/
• Enjoying Web Development with Wicket
– Kent Tong
– http://www.agileskills2.org/EWDW/
• Pro Wicket
– Karthik Gurumurthy
– http://apress.com/book/view/1590597222
– http://www.amazon.com/exec/obidos/tg/detail/-/1590597222/apachesoftwar-20/
40
![Page 41: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/41.jpg)
Links / References
• Wicket home:
– http://wicket.apache.org
• Wicket wiki
– http://cwiki.apache.org/WICKET/
• Wicket examples:
– http://www.wicketstuff.org/wicket13/
• Wicket impressions (blog post):
– http://ptrthomas.wordpress.com/2007/03/02/wicket-
impressions-moving-from-spring-mvc-webflow/
41
![Page 42: Migrating to Apache Wicket - WordPress.com...URL mapping XML Java Action Handler / Controller Security Acegi / Spring Sec. WebFlow Page Flow / Navigation ... •Easy integration with](https://reader034.vdocument.in/reader034/viewer/2022052613/5f131df9c33cec21a775dbe0/html5/thumbnails/42.jpg)
Wicket vs JSF• JSF in comparison:
– Not really OO components, more of XML tags than Java
– Added complexity of JSF-EL and mixing JSP-EL if applicable
– faces-config.xml : synchronize multiple files for navigation, page-centric, string
expressions not type-safe
– Poor separation of concerns / „preview-ability‟ (in core JSF spec)
– General consensus that for practical use you have to supplement with non-standard
extensions - e.g. Facelets, Spring WebFlow etc.
– Hard to unit test
– Hard to debug / step-through
– More dependence on tooling / IDE support
– Mixing components from multiple vendors problematic especially with AJAX
– Generated HTML is typically verbose
– Creating custom components is much harder
– Slow evolution as it is a specification, now JSF 2.0 is being discussed…
• More details, discussion and side-by-side comparison (with code):
– http://ptrthomas.wordpress.com/2007/05/14/a-wicket-user-tries-jsf/42