Wicket in Action: Martijn Dashorst Topicus B.V
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
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
www.javapolis.com
13
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
Joined Apache
www.javapolis.com 19
Popular?
Java Software Apache Software Foundation Web frameworks
www.javapolis.com
20
Projects
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
unity meetin gs
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
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
www.javapolis.com
22
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
www.javapolis.com
31
Component: 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
} }; 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
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
Label Component
Model Model
"John"
Label Component
Person Domain
www.javapolis.com
41
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
Summary
Just Java and HTML Easy Ajax Good testing support Great community
www.javapolis.com
Conclusion
Q&A
View JavaPolis talks @ www.parleys.com