0% found this document useful (0 votes)
428 views51 pages

Wicket in Action: Martijn Dashorst Topicus B.V

This document discusses the Apache Wicket framework. It begins with an overview of Wicket and its key concepts, including applications, sessions, request cycles, components, behaviors and models. It then demonstrates how to build a basic Wicket application and discusses features like Ajax support. Throughout it emphasizes that Wicket allows creating web apps using just Java and HTML through its component model and support for separation of logic and markup.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
428 views51 pages

Wicket in Action: Martijn Dashorst Topicus B.V

This document discusses the Apache Wicket framework. It begins with an overview of Wicket and its key concepts, including applications, sessions, request cycles, components, behaviors and models. It then demonstrates how to build a basic Wicket application and discusses features like Ajax support. Throughout it emphasizes that Wicket allows creating web apps using just Java and HTML through its component model and support for separation of logic and markup.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 51

Wicket in Action

Martijn Dashorst Topicus b.v.

Wicket in Action

Create web applications with just Java and HTML using Apache Wicket

www.javapolis.com

Martijn Dashorst
Software Engineer Committer Chair Co-author
Eelco Hillenius

www.javapolis.com

Agenda
What is Wicket? Wicket concepts Building a Wicket Application Q&A

www.javapolis.com

Wicket?

www.javapolis.com

Wicket?

www.javapolis.com

www.javapolis.com

Wicket
Home Introduction Planet Wicket Community News

Welcome to Apache Wicket


With proper mark-up/logic separation, a POJO data mod el, and a refreshing lack of makes developing web-apps XML, Apache Wicket simple and enjoyable again. Swap the boilerplate, complex brittle code for powerful, reus debugging and able components written with plain Java and HTML. Check the feature list Read some Wicket buzz, some Wicket blogs or Planet Wick et Find out why you should use Wicket Check out some selected exam ples in detail or see them and many more in live action Take a look at our live comp onent reference Go and download Wicket. Wicket is released under the Apache License, Version 2.0.

Getting Started
Examples Getting Wicket Components QuickStart

Documentation
Wiki Blogs Reference Vision JavaDocs

Community meetings
The Wicket community is a very active community. The mailing lists and the irc chan But for those that prefer face nel are proof of that. to face meetings, several comm unity members have organized meetups. Country Where When USA San Francisco to be determined Belgium Antwerp JavaPolis'07 (dec 12th -14th) The United Kingdom London The first Tuesday of every mon The Netherlands th Amsterdam ApacheCon EU'08 Denmark Copenhagen to be determined Austria Linz/Hagenberg to be determined Sweden Stockholm Januari Brazil Rio de Janeiro to be determined USA Minneapolis/Seattle to be determined If you are interested in atten ding one of these events, pleas e add yourself to the appropria you want to organize such a te event, or if meetup yourself, add it to the community meetups page

Releases
Wicket 1.3-rc Wicket 1.2 Wicket 1.1 Wicket 1.0

Tool support
IDE plugins

Developers

News

www.javapolis.com

Apache Wicket
Component oriented Open source Web application framework Java+HTML

www.javapolis.com

Hello, World!

Hello, World!
<h1 wicket:id=msg>[text goes here]</h1> + add(new Label(msg, Hello, World!)); = <h1>Hello, World!</h1>

www.javapolis.com

11

Hello, World!
<h1 wicket:id=msg>[text goes here]</h1> + add(new Label(msg, Hello, World!)); = <h1>Hello, World!</h1>

www.javapolis.com

12

A brief history of Wicket

www.javapolis.com

13

Discovery of the Hobbit Year of the monkey Milau bridge opens

2004

www.javapolis.com

15

2005
Airbus A380s maiden flight Huygens lands on Titan Dr. Who returns

www.javapolis.com

16

JavaOne05
Tapestry guy Bald guy Struts/Shale guy

Wicket 1.0
JSF guy WebWork guy Wicket guy
www.javapolis.com 17

2007
Joins Apache Software Foundation Releases 1.3 User groups start spawning

www.javapolis.com

18

Wicket uptake
Wicket 1.2 released

Wicket 1.0 released

Joined Apache
www.javapolis.com 19

Popular?
Java Software Apache Software Foundation Web frameworks

www.javapolis.com

20

Projects

core extensions ioc (spring, guice) date/time velocity auth-roles


www.javapolis.com

Wicket
Home Introduction Planet Wicket Community News

Getting Starte d
Examples Getting Wicket Components QuickStart

Documentatio

With proper mark-up/logic separation, a makes develop POJO data mod ing web -apps el, and a refr simple and enjo brittle code eshing lack of for powerful, yable again. XML, Apache reusable com Swap the boil Wicket ponents writ erplate, com ten with plai plex debugg Check the feat n Java and HTM ing and ure list L. Read some Wic ket buzz, som e Wicket blog Find out why s or Planet Wic you should use ket Wicket Check out som e selected exa mples in deta Take a look at our live com il or see them and many mor ponent referenc Go and downloa e in live acti e d Wicket. on Wicket is rele ased under the Apache License , Version 2.0. Comm

Welcome to Apache Wicket

unity meetin gs

Wiki Blogs Reference Vision JavaDocs

Releases
Wicket 1.3rc Wicket 1.2 Wicket 1.1 Wicket 1.0

Tool suppor t
IDE plugins

Developers
Reporting bug s Writing docs Building

The Wicket com munity is a very But for those active commun that prefer face ity. The mailing to face meeting lists and the s, several com irc channel are munity mem proof of that bers have orga . Where nized meetups London, The . United Kingdom When Amsterdam, The first Tue The Netherland sday of ever s y month Antwerp, Belg Nov. 30th, 200 ium 7 Copenhagen, JavaPolis'07 Denmark (dec 12th -14 th) Linz/Hagenberg to be determin , Austria ed Stockholm, Swe to be determin den ed Rio de Janeiro, Januari Brazil Minneapolis/Se to be determin attle, USA ed to be determin If you are inte ed rested in atte nding one of you want to these events, organize such please add you a meetup you rself to the app rself, add it to the commun ropriate even News t, or if ity meetups page

Nov 11, 200 7

Apache Wicket 1.3.0-rc1 is released!

This release is the first in a series of rele ase candidates until we feel confident to finalize Wicket 1.3. This

21

Getting Wicket

Everybody gets the ultimate edition Includes:


sources projects examples

Currently 1.3-rc2 Or...

www.javapolis.com

22

Using maven to get Wicket

<dependency> <groupId>org.apache.wicket</groupId> <artifactId>wicket</artifactId> <version>1.3.0-rc2</version> </dependency>

www.javapolis.com

23

Agenda
What is Wicket? Wicket concepts Building a Wicket Application Q&A

www.javapolis.com

24

Concepts
Application Session RequestCycle Components Behaviors Models
www.javapolis.com 25

Application

Main entry point for your web application Initialization Configuration Homepage Factories Configured in web.xml

www.javapolis.com

26

Concepts
Application Session RequestCycle Components Behaviors Models
www.javapolis.com 27

Concepts
Application Session RequestCycle Components Behaviors Models
www.javapolis.com 28

Concepts
Application Session RequestCycle Components Behaviors Models
www.javapolis.com 29

Components

Encapsulate the programmatic manipulation of markup Render content in the response Receive events in the request
onClick, onSubmit

Lots of em:
Label, MultiLineLabel, TextField, PasswordTextField, Image, Link, AjaxLink, AjaxFallbackLink, Tree, BookmarkablePageLink, ListView, RepeatingView, PagingNavigator, Button, ...
www.javapolis.com 30

Components

Component has wicket:id Markup has same wicket:id Hierarchy must match

<h1 wicket:id=msg>Gets replaced</h1> new Label(msg, Hello, World!);

www.javapolis.com

31

Component: Link

<a href=# wicket:id=link>Click</a> Link link = new Link(link);

add(link);
www.javapolis.com 32

Component: Link

<a href=# wicket:id=link>Click</a> Link link = new Link(link) { @Override public void onClick() { // do something setResponsePage(new NewPage()); } }; add(link);
www.javapolis.com 33

Component: AjaxLink

<a href=# wicket:id=link>Click</a>

AjaxLink link = new AjaxLink(link) { public void onClick(AjaxRequestTarget t) { // do something

} }; add(link);
www.javapolis.com 34

Component: AjaxLink

<a href=# wicket:id=link>Click</a> someComponent.setOutputMarkupId(true); AjaxLink link = new AjaxLink(link) { public void onClick(AjaxRequestTarget t) { // do something t.addComponent(someComponent); t.appendJavaScript(Effects.fade(foo);); } };
www.javapolis.com 35

Component + Markup

Some components have own markup file


Page, Panel, Border

Put Java, markup and supporting files in same package on class path
www.javapolis.com 36

Concepts
Application Session RequestCycle Components Behaviors Models
www.javapolis.com 37

Behaviors

Plugins for components Change attributes of your components markup Add javascript events Add Ajax behavior
component.setOutputMarkupId(true); component.add( new AjaxSelfUpdatingBehavior(Duration.seconds(5)));

www.javapolis.com

38

Behaviors

link.add(new AbstractBehavior() { public void onComponentTag( Component component, ComponentTag tag) { tag.put(onclick, return confirm(Are you sure?);); } }); Output: <a href=... onclick=return confirm(....);>...</a>

www.javapolis.com

39

Concepts
Application Session RequestCycle Components Behaviors Models
www.javapolis.com 40

Models

Models bind your POJOs to Wicket components

Label Component

Model Model

"John"

Label Component

PropertyModel Model expression: "name"

Person Domain

www.javapolis.com

41

Java lazy binding sucks

Doesnt update: new Label(name, person.getName()) Null checks necessary: new Label(street, person.getAddress().getStreet())

www.javapolis.com

42

Models

PropertyModel:
new PropertyModel(p, name) new PropertyModel(p, address.street)

CompoundPropertyModel:
setModel(new CompoundPropertyModel(p)); add(new Label(name)); add(new Label(address.street));

www.javapolis.com

43

Agenda
What is Wicket? Wicket concepts Building a Wicket Application Q&A

www.javapolis.com

44

DEMO

Agenda
What is Wicket? Wicket concepts Building a Wicket Application Q&A

www.javapolis.com

46

Wicket in Action

Wicket in Action
Eelco Hillenius Martijn Dashorst ISBN: 1-932394-98-2 ~375 pages MEAP + E-book: $27.50 MEAP + Dead tree: $49.90

0% ! Use coupon code 3 f of HC230 at checkout


www.javapolis.com 47

Summary

Apache Wicket is:


a furry animal three sticks with stumps a component oriented web application framework

Just Java and HTML Easy Ajax Good testing support Great community

www.javapolis.com

Conclusion

Wicket is good for my sex life


Seriously, I also have a wife and kid. And the productivity gained from implementing in Wicket is unsurpassed. The extraordinary diagnostics available is worth it alone. OOP isn't bastardized within this framework, it is embraced... n n
http://www.theserverside.com/news/thread.tss?thread_id=34725#175612
www.javapolis.com

Q&A
View JavaPolis talks @ www.parleys.com

Thank you for your attention

You might also like