Académique Documents
Professionnel Documents
Culture Documents
Nino Martinez
Wicket contrib input events Wicket contrib Openlayers Wicket contrib BBCode Wicket contrib Gmap Wicketstuff minis Wicketstuff Iolite More in progress!
Have worked very intensely with wicket for the last 3 years Written several articles / screen casts on misc Wicket topics @ ninomartinez.wordpress.com
Teaser
EASY (SIMPLE / CONSISTENT / OBVIOUS)
POJO-centric
All code written in Java ala Swing Avoid overuse of XML configuration files Minimum reliance on special tools Components, containers and conventions should be consistent Components written in Wicket should be fully reusable Reusable components should be easily distributed in ordinary JAR files HTML or other markup not polluted with programming semantics Compatible with any ordinary HTML editor Code is secure by default Easy to integrate with Java security Efficient and lightweight, but not at the expense of other goals Clustering through sticky sessions preferred Clustering via session replication is easy to accomplish.
REUSABLE
NON-INTRUSIVE
SAFE
EFFICIENT / SCALABLE
Wicket Introduction
Content When we go over the sections below we are going to implement a very basic blog application
History Theory Web-Application Components Behavior & Panel Markup inheritance Internationalization (i18n) Forms (input and validation) Testing Ajax Beyond basics Additional Resources
History of Wicket
Wicket was conceived in Jonathan Locke's study back in 2004, shortly after open sourced at Codehaus, then sourceforge and in 2006 it incubated to a real Apache project. Top level project at Apache today The name wicket is not the little guy from Star Wars but a term from cricket meaning a small framework at which the bowler aims the ball.
Theory
Apache Wicket is a object oriented stageful web framework, working with it are just plain java! Mapping between html tags and wicket components One .html has one .java (almost always true) Single threaded(session scope) request cycle as standard
Sample Code
Java: Label label=new Label(label,hello world); Html: <span wicket:id=label></span> Result: <span>hello World</span>
Theory
Models?
Sample Code Java: Label label=new Label(label,new Model(new HelloObject())); Html: <span wicket:id=label></span> Result: <span>hello World</span>
mvn archetype:generate -DarchetypeGroupId=org.wicketstuff.iolite -DarchetypeArtifactId=wicketstuff-iolite -DarchetypeVersion=0.3-SNAPSHOT -DarchetypeRepository=http://wicketstuff.org/maven/repository -DgroupId=com.mycompany -DartifactId=myproject -Dpackage=com.mycompany -Dversion=1
Demo Setup
What did I do Run archetype generation
Domain Logic Stylesheet Edited base page, to provide a basic layout Two module project
Web-Application
A Wicket web application consists of
a class that extends webapplication a corresponding web.xml which points at the webapplication some pages Homepage (default page redirected to) Session (session object could be used for authentication) Mounted urls Spring injection Lots more can happen here.
Holds configuration
Components
Page Label ListView Link Wicket Core, Wicket Extensions, Wicketstuff If a component contains children you must add them to the component, for example a form. Hierarchy is the same as DOM / HTML
Code time:)
Let's create a Listview iterating over authors and posts
Markup Inheritance
Wicket supports markup inheritance Which means that a page can extend another page Usage (java side we know using the extends keyword)
Code time:)
Lets see how it's used in our blog application.
Internationalization
Resource models Property Files
Just use standard java I18n naming of property files Examples: myPage.properties myPage_da.properties myPage_th.xml
Usage
In page or panel html part
Forms
Validation
Required More, or roll your own? Radio Check List Text Palette ...
Controls
Code time:)
Time for authentication, lets do a Login form on the login page And do the AuthorPage with a form so we can post posts.
Testing
Wicket provides some simple facilities to make tests
Wicket Tester
Simulates Http requests Allows you to make wicket specific assertions Allows you to manipulate forms
Wicket FormTester
Code time:)
Let's examine a test case that tests our LoginPage & AuthorPage flow..
Ajax
Adding Ajax to wicket is a breeze, just add a ajaxBehavior and thats it. Sometimes though you can use one of the Ajax controls instead. Sample Code
AjaxButton ajaxBtn = new AjaxButton("ajaxButton") { @Override protected void onSubmit(AjaxRequestTarget target, Form form) { } @Override protected void onError(AjaxRequestTarget target, Form form) { target.addComponent(feedbackPanel); } };
Code time:)
Time to Ajax-ify our home page, let's refresh our Author/post overview at a given interval.
Protecting against CSRF, with CryptedUrlWebRequestCodingStrategy, set it in WebApplication.java IVisitor, visit your components. Good for visiting multiple children and perhaps modifying them, like for example changing styles based on validation etc.
Quickstart (official), sets up wicket naked.. WicketStuff Iolite (wicketstuff), sets up wicket with JPA(Hibernate) and Spring