Title: Apache Wicket
1Apache Wicket
2Web Development withjust Java
3Gerolf Seitz
- Since Sept.07
- Committer
- PMC
- MSc student (almost finished)
- Software Engineer at Software Competence Center
Hagenberg GmbH, Upper Austria
4Agenda
- What is Wicket?
- Core Concepts
- Developing a custom Component
- Summary
- QA
5Agenda
- What is Wicket?
- Core Concepts
- Developing a custom Component
- Summary
- QA
6Wicket in a Nutshell
- Open Source
- Component oriented
- Web application framework
- Java HTML
7Features
- Everything in Java
- State management
- Safe URLs
- Nice URLs (mounting)
- OOTB support for
- Clustering
- Portlet
8Features
- Reusable components
- Nested forms
- No more double submit of forms
- Back-button-support
- I18n
- WicketTester
9Features
- Ajax "without" JavaScript
- Header Contributions
- JavaScript CSS
- Component level security
10Hello, World!
- lth1 wicketid"msg"gttext goes herelt/h1gt
11Hello, World!
- lth1 wicketid"msg"gttext goes herelt/h1gt
-
- add(new Label("msg", "Hello, World!"))
12Hello, World!
- lth1 wicketid"msg"gttext goes herelt/h1gt
-
- add(new Label("msg", "Hello, World!"))
-
- lth1gtHello, World!lt/h1gt
13Hello, World!
- lth1 wicketid"msg"gttext goes herelt/h1gt
-
- add(new Label("msg", "Hello, World!"))
-
- lth1gtHello, World!lt/h1gt
14Hello, World!
- lth1 wicketid"msg"gttext goes herelt/h1gt
-
- add(new Label("msg", "Hello, World!"))
-
- lth1gtHello, World!lt/h1gt
15Brief History
- 2004 The First Encounter
- 2005 JavaOne'05 Smackdown
- 2006 Incubation at ASF
16Brief History
- 2007 Graduation
- 2007 1.3 released
- 2007 WUGs start spawning Amsterdam meetup 80
attendees
17Projects
- core
- extensions
- ioc (spring, guice)
- date/time
- velocity
- jmx
18Getting Wicket
- Current Release 1.3.3
- ltdependency
- groupId"org.apache.wicket"
- artifactId"wicket"
- version"1.3.3"
- /gt
19Getting Wicket - Quickstart
http//wicket.apache.org/quickstart.html
20Agenda
- What is Wicket?
- Core Concepts
- Developing a custom Component
- Summary
- QA
21Core Concepts
- Application
- Session
- RequestCycle
- Components
- Behaviors
- Models
22Application
- Main entry point
- Initialization
- Configuration
- Factories
- Homepage
- Configured in web.xml
23Application
- ltfiltergt
- ltfilter-namegtwicketlt/servlet-namegt
- ltfilter-classgt org.apache.wicket.protocol.http.
WicketFilter - lt/filter-classgt
- ltinit-paramgt
- ltparam-namegtapplicationClassNamelt/param-namegt
- ltparam-valuegtexample.MyApplicationlt/param-value
gt - lt/init-paramgt
- ltload-on-startupgt1lt/load-on-startupgt
- lt/filtergt
24Core Concepts
- Application
- Session
- RequestCycle
- Components
- Behaviors
- Models
25Session
- Abstraction of a user session
- Stores session specific data
- Strongly typed session attributes
26Core Concepts
- Application
- Session
- RequestCycle
- Components
- Behaviors
- Models
27RequestCycle
- Stateful
- Tied to specific user session
- Not (typically) bookmarkable
- Stateless
- Not necessarily tied to specific user session
- Bookmarkable
28Core Concepts
- Application
- Session
- RequestCycle
- Components
- Behaviors
- Models
29Components
- Basic building blocks
- Encapsulate the programmatic manipulation of
markup - Render content
- Receive events
- onClick, onSubmit
30Components lots of em
- Label, MultiLineLabel, TextField,
PasswordTextField, Image, Link, AjaxLink,
AjaxFallbackLink, Button, AjaxButton, DatePicker,
ListView, RefreshingView, DataGrid, DataTable,
Tree, GMap, Wizard, JasperReports, ...
31Components
- Component has wicketid
- Same wicketid in markup
- Hierarchy must match
- lth1 wicketidmsggtgets replacedlt/h1gt
- new Label(msg, Hello World!)
32Component Link
- lta href"" wicketid"link"gtClicklt/agt
- Link link new Link("link")
- add(link)
33Component Link
- lta href"" wicketid"link"gtClicklt/agt
- Link link new Link("link")
- _at_Override public void onClick()
- //do something
- setResponsePage(new NewPage())
-
-
- add(link)
34Component AjaxLink
- lta wicketid"link"gtClicklt/agt
- AjaxLink link new AjaxLink("link")
- public void onClick(AjaxRequestTarget t)
- //do something
-
-
- add(link)
35Component AjaxLink
- lta wicketid"link"gtClicklt/agt
- someComponent.setOutputMarkupId(true)
- AjaxLink link new AjaxLink("link")
- public void onClick(AjaxRequestTarget t)
- //do something
- t.addComponent(someComponent)
- t.appendJavascript("Effects.fade('foo')")
-
-
- add(link)
36Components
- Components with own markup
- Page, Panel, Border
- Java and markup files in same package on classpath
37Core Concepts
- Application
- Session
- RequestCycle
- Components
- Behaviors
- Models
38Behaviors
- Plugins for components
- Change attributes of your components markup
- Add Javascript events
- Add Ajax behavior
- timeLabel.add(
- new AjaxSelfUpdatingTimerBehavior(
- Duration.seconds(5)))
39Behaviors
- link.add(new AbstractBehavior()
- public void onComponentTag(Component component,
ComponentTag tag) - tag.put("onclick",
- "return confirm('Are you sure?')")
-
- )
- Output
- lta href"..." onclick"return confirm('...')"gt...
lt/agt
40Core Concepts
- Application
- Session
- RequestCycle
- Components
- Behaviors
- Models
41Models
- Bind POJO's to Wicket components
new Label("name", model)
ltltPersongt name String city String
Model
42Models
- Lazy binding in Java sucks
- Doesn't update
- new Label("name", person.getName())
- Null checks necessary
- new Label("street", person.getAddress().getStreet
()) - Solution OGNL/EL like expressions
43Models
- PropertyModel
- new PropertyModel(person, name)
- new PropertyModel(person, address.street)
- CompoundPropertyModel
- setModel(new CompoundPropertyModel(p))
- add(new Label("name"))
- add(new Label("address.street"))
44Agenda
- What is Wicket?
- Core Concepts
- Developing a custom Component
- Summary
- QA
45Custom Components
- Eelco Hillenius
- Imagine being told that you can use Java as
your programming language, but at the same time
being told not to create your own classes. ... - I fail to understand why that has to be
different for UI development, and Wicket proves
it doesn't have to be so.
46PasswordStrenghIndicator
lthtmlgt ltheadgt lttitlegtInsert title
herelt/titlegt ltwicketheadgt ltwicketlinkgt
ltlink rel"stylesheet" type"text/css"
href"res/PasswordField.css"/gt lt/wicketlinkgt
lt/wicketheadgt lt/headgt ltbodygt ltwicketpanelgt
ltinput wicketid"password" type"password"
/gtltspan wicketid"strength"gtstrengthbarlt/spangt
lt/wicketpanelgt ltdivgt lthr/gt Examplesltbr
/gt ltinput type"password" /gt ltspan
class"weak"gtnbsplt/spangt (weak)ltbr/gt ltinput
type"password" /gt ltspan class"medium"gtnbsplt/sp
angt (medium)ltbr/gt ltinput type"password" /gt
ltspan class"strong"gtnbsplt/spangt
(strong)ltbr/gt lt/divgt lt/bodygt lt/htmlgt
47PSI - Markup
- ltwicketheadgt
- ltwicketlinkgt
- ltlink rel"stylesheet" type"text/css"
href"res/PasswordField.css"/gt - lt/wicketlinkgt
- lt/wicketheadgt
- ltwicketpanelgt
- ltinput wicketid"password" type"password" /gt
ltspan wicketid"strength"gtstrengthbarlt/spangt - lt/wicketpanelgt
48PSI - Java
- public class PasswordField extends Panel
- public final static String WEAK "weak"
- public final static String MEDIUM "medium"
- public final static String STRONG "strong"
-
- public PasswordField(String id, IModel model)
- super(id, model)
- PasswordTextField passwordTextField new
PasswordTextField("password", model) - add(passwordTextField)
-
- final Label strength new Label("strength",
"") - add(strength)
- strength.add(new AttributeModifier("class",
true, new Model() - public Object getObject()
- return getPasswordStrength(PasswordField.this.
getModelObjectAsString()) -
- ))
-
- strength.setOutputMarkupId(true)
49PSI - TestPage
- public class TestPage extends WebPage
- private String password
- public TestPage()
- Form form new Form("form")
- form.add(new PasswordField("password", new
PropertyModel(this, "password"))) - add(form)
-
50Agenda
- What is Wicket?
- Core Concepts
- Developing a custom Component
- Summary
- QA
51Summary
- Component oriented web application framework
- Just Java and HTML
- Easy Ajax
- Enthusiastic community
52Community
- http//wicket.apache.org
- users_at_wicket.apache.org
- wicket_at_irc.freenode.net
53Future Wicket NEXT
- Java 5 based
- Generics (already in)
- Varargs?
- Typesafe PropertyModel
- New WicketTester
- Based on JDave/Hamcrest
- Many more cool features
54Books
55Agenda
- What is Wicket?
- Core Concepts
- Developing a custom Component
- QA
56Thank you for yourattention