Introduction to the component based Wicket Framework which is used to create Java Web Applications. More information can be found at : https://www.spiraltrain.nl/course-wicket-programming/?lang=en
3. www.spiraltrain.nl
What is Wicket?
• Wicket is a Component Oriented Web Application framework :
• Web Development done with pure Java and pure HTML
• Brings object oriented programming to the view layer :
• Re-applies Model View Controller pattern on components instead of requests
• Follows traditional model for UI development on thick clients :
• Unlike traditional Web Application frameworks like Struts and Spring MVC
• Clean separation of concerns between HTML and Java
• Enables component-oriented, programmatic manipulation of markup
• HTML not polluted with programming semantics :
• Only simple tagging constructs in markup
• Open Source Framework of Apache Software Foundation :
• Enthusiastic developer community
• Name “Wicket” means “gate” and is easy to remember :
• Lightweight door in immovable Java EE gate
3Wicket Intro
4. www.spiraltrain.nl
Component Orientation
• Wicket is a Component Oriented Framework :
• Build a model of requested page on the server side
• HTML sent back to the client is generated according to this model
• Model can be thought of as an “inverse” JavaScript DOM :
• Model is built on server-side
• Model is built before HTML is sent to client
• HTML code is generated using this model and not vice versa
• Web pages and HTML input controls are instances :
• Live inside the JVM heap and can be handled like other Java classes
• Approach is similar to how GUI Framework like Swing works
Wicket Intro 4
Client requests
a page
Page model is
created by
framework
Html is generated
according to page
model
Html is returned
to the client
5. www.spiraltrain.nl
Wicket Features
• Based on Plain Old Java Objects (POJO‘s) :
• All code written in Java like in Swing GUI with maximum type safety
• Requires minimal configuration :
• Avoids overuse of XML configuration files
• Web Form support with :
• Nested forms and no more double submit of forms
• Offers Ajax functionality "without" JavaScript :
• Fully solves back button problem and has Ajax Debug Window
• Easy to create bookmarkable pages
• Page composition :
• Panels, borders and markup inheritance
• Excellent I18n localization and style support :
• Automatic client capabilities detection and template and resource loading
• Offers fancy components out of the box :
• Data aware tables, date picker, Google Maps tabbed panel, tree, wizard
5Wicket Intro
6. www.spiraltrain.nl
More Wicket Features
• Easy to integrate with Java security :
• Offers component level security
• Can integrate with many other frameworks :
• Spring, Guice, Hibernate, JasperReports, OSGi
• Easy creation and use of custom components :
• Reusable components
• URL Handling :
• Safe URLs and Nice URLs (mounting) pretty URLs
• JUnit testing :
• WicketTester Testing support
• And the following as well :
• Out of the Box support for clustering
• State management through type safe sessions
• Extensive logging and error reporting facilities
• Header contribution Javascript and CSS
6Wicket Intro
7. www.spiraltrain.nl
Wicket Timeline
• 2004 :
• First Encounter, Jonathan Locke envisioned and originated Wicket
• 2005 :
• Demonstrated at JavaOne 05
• 2007 :
• Adopted at Apache Software Foundation, WUG‘s start spawning
• 2008 :
• Version1.3 released with many improvements
• 2009 :
• Version 1.4 requires Java 5 as the minimum JDK version, generics support
• 2012 :
• Version 1.6 brings jQuery integration, complete control over AJAX requests
• 20015 :
• Version Wicket 7 released
• 20019 :
• Milestone version Wicket 9 released
Wicket Intro 7
8. www.spiraltrain.nl
Component Hierarchy
• Wicket :
public class HelloWorld extends WebPage {
public HelloWorld() {
add(new Label("message", "Hello, World!"));
}
}
• Swing :
public class HelloWorld extends JFrame {
public HelloWorld() {
add(new Label("Hello, World!"));
}
}
8Wicket Intro
13. www.spiraltrain.nl
General Application Structure
• Markup in HTML files :
• Layout the element hierarchy
• Style the elements
• Code in Java classes :
• Mirror and implement markup's element hierarchy
• Event handling
• Property files with auxiliary role :
• Strings and internationalization
• Logging in e.g. log4j.properties
• Application Configuration :
• In web.xml of Java Web Application
• Application initialization :
• In init method of Application class
13Wicket Intro
14. www.spiraltrain.nl
Wicket Run Modes
• Development mode :
• Exceptional error pages, Dynamic markup reloading, No caching
• No JavaScript/CSS Optimizations, Wicker Debugger visible
• Discover mistakes early (serialization, missing components)
• Wicket warns when running in development mode as follows :
********************************************************************
*** WARNING: Wicket is running in DEVELOPMENT mode. ***
********************************************************************
• Deployment mode :
• Cache markup resources, No checks, Don’t display stack traces to users
• Minimize and compress JavaScript, Don’t generate Wicket tags
• Wicket Debugger not visible
• Do not run an application in production using development mode
• Change by setting context parameter in web.xml :
<context-param>
<param-name>configuration</param-name>
<param-value>deployment</param-value>
</context-param>
Wicket Intro 14
15. www.spiraltrain.nl
• Download Wicket Binaries Library :
• from http://wicket.apache.org/
• Or
• Use Maven :
<dependency>
<groupid>org.apache.wicket</groupid>
<artifactid>wicket-core</artifactid>
<version>${wicket.version*}</version>
</dependency>
Wicket Intro 15
Setting Up Wicket
16. www.spiraltrain.nl
Wicket in IDE’s
• NetBeans includes Maven support :
• Start directly by just opening the folder containing our project
• Intellj IDEA comes with a Maven importing functionality :
• Started under “File/New Project/Import from external model/Maven”
• Next just select pom.xml file of our project
• Eclipse import procedure :
• Select import maven project and point to pom.xml file
• Classpath variable MAVEN_HOME should point to local Maven repository
Wicket Intro 16
17. www.spiraltrain.nl
Wicket Distribution and Modules
Module name Description
wicket-core Contains the main classes of the framework, like class Component and Application
wicket-request This module contains the classes involved into web request processing.
wicket-util Contains general-purpose utility classes for functional areas such as I/O, lang, string
manipulation, security, etc...
wicket-datetime Contains special purpose components designed to work with date and time
wicket-bean-validation Provides support for JSR 303 standard validation
wicket-devutils Contains utility classes and components to help developers with tasks such as
debugging, class inspection and so on
wicket-extensions Contains a vast set of built-in components to build a rich UI for our web application (Ajax
support is part of this module)
wicket-auth-roles Provides support for role-based authorization
wicket-ioc This module provides common classes to support Inversion Of Control. It's used by both
Spring and Guice integration module
wicket-guice Provides integration with the dependency injection framework developed by Google
wicket-spring This module provides integration with Spring framework
wicket-velocity Provides panels and utility class to integrate Wicket with Velocity template engine
wicket-jmx Provides panels and utility class to integrate Wicket with Java Management Extensions
wicket-objectsizeof-agent Provides integration with Java agent libraries and instrumentation tools
Wicket Intro 17
18. www.spiraltrain.nl
Wicket Resources
• Homepage : http://wicket.apache.org
• Documentation : https://code.google.com/p/wicket-guide
• Wiki : https://cwiki.apache.org/WICKET
• Source code : https://github.com/apache/wicket
• Demo site : http://www.wicket-library.com
• Official user list : users@wicket.apache.org
• Official development list : dev@wicket.apache.org
• Official forum : http://apache-wicket.1842946.n4.nabble.com
• Official IRC channel : irc.freenode.net ##wicket channel
• Users FAQ : http://cwiki.apache.org/WICKET/faqs.html
• Why Wicket? article at http://wicket.apache.org/meet/introduction
• Confluence : https://cwiki.apache.org/confluence/display/WICKET/
• Twitter accounts of :
• Jonathan Locke, Igor Vaynberg, Martijn Dashorst, Eelco Hillenius
18Wicket Intro