Presentation on Apache Wicket delivered at JavaPolis 2007 in Antwerp. We introduce Wicket, learn the concepts and go through developing an online Cheese store
10. Wicket Welcome to Apache Wicket
Home With proper mark-up/logic
separation, a POJO data mo
Introduction del, and a refreshing lack of
makes developing web -apps XML, Apache Wicket
simple and enjoyable again.
Swap the boilerplate, comple
Planet Wicket brittle code for powerful, reu x debugging and
sable components written wit
h plain Java and HTML.
Community
Check the feature list
News Read some Wicket buzz, som
e Wicket blogs or Planet Wic
ket
Find out why you should use
Wicket
Getting Started Check out some selected exa
mples in detail or see them
and many more in live action
Take a look at our live compon
Examples ent reference
Go and download Wicket .
Getting Wicket
Wicket is released under the
Components Apache License, Version 2.0
.
QuickStart
Community meetings
Documentation
The Wicket community is a
very active community. The
mailing lists and the irc cha
But for those that prefer fac nnel are proof of that.
Wiki e to face meetings, several com
munity members have organi
zed meetups.
Blogs
Country
Where
Reference
When
USA
San Francisco
Vision to be determined
Belgium
Antwerp
JavaDocs JavaPolis'07 (dec 12th-14th
)
The United Kingdom
London
The first Tuesday of every mo
Releases The Netherlands nth
Amsterdam
ApacheCon EU'08
Denmark
Copenhagen
Wicket 1.3-rc to be determined
Austria
Linz/Hagenberg
Wicket 1.2 to be determined
Sweden
Wicket 1.1 Stockholm
Januari
Brazil
Wicket 1.0 Rio de Janeiro
to be determined
USA
Minneapolis/Seattle
to be determined
Tool support
If you are interested in attendi
ng one of these events, please
add yourself to the appropriat
IDE plugins you want to organize such a e event, or if
meetup yourself, add it to the
community meetups page
News
Developers
www.javapolis.com 9
11. Apache Wicket
Component oriented
Open source
Web application framework
Java+HTML
www.javapolis.com 10
34. Projects
core
Wicket
Welcome to
Apache Wick
et
Home
With proper
Introduction mark-up/logic
extensions
separation, a
makes devel
Planet Wick POJO data mo
oping web-ap
et del, and a ref
ps simple an
brittle code
reshing lack
d enjoyable
for powerful,
Community again. Swap of XML, Apach
reusable comp the boilerplate e Wicket
onents writte , complex de
n with plain
Check the fea bugging and
News Java and HTML
ture list .
Read some Wi
cket buzz, so
Getting Star me Wicket blo
Find out why
ted gs or Planet
you should us Wicket
e Wicket
Check out so
me selected
examples in
Examples Take a look detail or see
at our live co them and ma
mponent ref
Getting Wick Go and down ny more in live
erence
et load Wicket. action
Components
Wicket is rel
eased under
ioc (spring, guice)
QuickStart the Apache Lic
ense, Version
2.0.
Commun
ity meetings
Documentatio
n
The Wicket co
mmunity is a
Wiki very active co
But for those mmunity. Th
that prefer fac e mailing list
e to face me
Blogs s and the irc
etings, severa channel are
l community proof of that.
Reference members ha
ve organized
Where meetups.
London, The
Vision United Kingd
om When
JavaDocs Amsterdam, The first Tuesd
The Netherla
nds ay of every mo
Antwerp, Belgi nth
date/time
Nov. 30th, 20
um
Releases 07
Copenhagen JavaPolis'07
, Denmark
(dec 12th-14
Wicket 1.3-r th)
Linz/Hagenbe
c to be determi
rg, Austria ned
Wicket 1.2 Stockholm, Sw to be determi
eden ned
Wicket 1.1 Rio de Janeir Januari
o, Brazil
Wicket 1.0 Minneapolis/ to be determi
Seattle, USA
ned
Tool suppor to be determi
If you are int ned
t erested in att
ending one of
you want to these events
organize such
IDE plugins , please add
a meetup yo yourself to the
urself, add it
velocity
appropriate
to the comm
News event, or if
unity meetups
Developers page
Apache Wick
Reporting bu et 1.3.0-rc1
gs
is released!
Writing docs
Nov 11, 2007
Building
This release
is the first in
a series of rel
ease candidate
s until we fee
l confident to
finalize Wicke
t 1.3. This
auth-roles
www.javapolis.com 22
36. Using maven to get Wicket
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket</artifactId>
<version>1.3.0-rc2</version>
</dependency>
www.javapolis.com 24
37. Agenda
What is Wicket?
Wicket concepts
Building a Wicket Application
Q&A
www.javapolis.com 25
39. Application
Main entry point for your web application
Initialization
Configuration
Homepage
Factories
Configured in web.xml
www.javapolis.com 27
43. 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 31
44. 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 32
45. Component: Link
<a href=”#” wicket:id=”link”>Click</a>
Link link = new Link(“link”);
add(link);
www.javapolis.com 33
46. 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 34
47. 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 35
48. 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 36
49. 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 37
54. Models
Models bind your POJO’s to Wicket
components
Component Model
Component Model Domain
www.javapolis.com 42
55. Models
Models bind your POJO’s to Wicket
components
Label Model quot;Johnquot;
PropertyModel
Label Person
expression: quot;namequot;
www.javapolis.com 42
56. Java lazy binding sucks
Doesn’t update:
new Label(“name”, person.getName())
Null checks necessary:
new Label(“street”,
person.getAddress().getStreet())
www.javapolis.com 43
93. Reuse the shopping cart
Create ShoppingCartPanel.html
Create ShoppingCartPanel.java
Move cart markup to
ShoppingCartPanel.html
Move cart Java code to
ShoppingCartPanel.java
Use panel in home page and checkout page
www.javapolis.com 80
98. CheckOutPage: add Form
<form>
<h3>Check out</h3>
<p>Please enter your billing address.</p>
<form wicket:id=”form”>
<h3>Check out</h3>
<p>Please enter your billing address.</p>
add(new Form(quot;formquot;) {
@Override public void onSubmit() {
// do something with the order
setResponsePage(FrontPage.class);
}
}); www.javapolis.com 85
102. Create unit test for shopping cart
public void testRemove() {
WicketTester tester = new WicketTester();
final Cart cart = new Cart();
cart.getContents().add(Cheese.getCheeses().get(0));
cart.getContents().add(Cheese.getCheeses().get(1));
List<Cheese> expected = new ArrayList<Cheese>();
expected.add(Cheese.getCheeses().get(0));
expected.add(Cheese.getCheeses().get(1));
tester.startPanel(new TestPanelSource() {
public Panel getTestPanel(String panelId) {
return new ShoppingCartPanel(panelId, cart);
}
});
tester.assertListView(quot;panel:contentsquot;, expected);
tester.clickLink(quot;panel:contents:0:removequot;);
expected.remove(0);
tester.assertListView(quot;panel:contentsquot;, expected);
}
www.javapolis.com 89
103. Agenda
What is Wicket?
Wicket concepts
Building a Wicket Application
Q&A
www.javapolis.com 90
104. 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
3f
f HC230 at checkout
o
www.javapolis.com 91
105. 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
106. 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