Wicket Tutorial
Apache Wicket is a simple and features rich component-based web framework, the real reusable components is the main selling point of this framework. However, due to the big different between component-based and MVC architecture, it makes Wicket hard to learn, especially for those classic MVC developers.
In this tutorials, it providing many step by step examples and explanations on using Apache Wicket 1.4.
Basic & Configuration
Wicket hello world, basic stuff and URL configuration.
-
Wicket Hello World Example
A simple hello world to explore the basic structure of Wicket web application. -
Setup Wicket examples in local enviroment
Setup a cloned Wicket example site in your local development environment for quick reference. -
PageParameters example
Learn how to pass parameters to another page. -
Make Wicket URL bookmarkablePage Structure friendly
By default, Wicket generated URL is ugly, here is a way to make the URL more neat and friendly. -
Encrypts URL in Wicket
Easy way to encrypt URLs in Wicket.
Model
Wicket model examples, to bind from components to object property, and vise verse.
-
PropertyModel example
Uses PropertyModel to bind form components to object property. -
CompoundPropertyModel example
Uses CompoundPropertyModel to bind form components to object property.
Form Components
Wicket form component examples.
-
Textbox example
Uses TextField to render a username textbox, and attached a simple username validator. -
Password field example
Uses PasswordTextField to render password field, and attached a strong password validator. -
Textarea example
Uses TextArea to render a multi-lines address field. -
Checkbox example
Uses Checkbox to render checkbox, and checked it by default. -
Multiple checkboxes example
Uses CheckBoxMultipleChoice to render multiple checkboxes. -
Radio buttons example
Uses RadioChoice to render a group of radio buttons. -
Single select listbox example
Uses ListChoice to render a single select scrollable list. -
Multi select listbox example
Uses ListMultipleChoice to render a multi select scrollable list. -
Dropdown box example
Uses DropDownChoice to render a dropdown box options. -
File upload example
Uses FileUploadField to render a file upload componenet. -
Select and SelectOption example
Wicket extensions – uses “Select” and “SelectOption” to render a dropdown box, which group related options with <optgroup> tags. -
Palette example
Wicket extension – uses “Palette” to render two select boxes, and allow user to move items from one select box into another.
Validators
Custom validator in Wicket.
-
Create a custom validator
Example to create a custom validator. -
Custom NotEqualInputValidator
Another custom validator to make sure two components are not equal.
Wicket Integration
Integrate Wicket with others.
-
Wicket + Spring integration example
Example to integrate Wicket with Spring framework easily. -
Wicket + Kaptcha integration example
Example to integrate Kaptcha with Wicket framework, via Spring. -
Wicket + Log4j integration example
How to integrate log4j with Wicket, via slf4j-log4j bridge binding.
FAQs
Some common FAQs in Wicket.
-
Change the html file location in Wicket
For some reasons, you want to separate java and html file into different folder, here are few ways to do it. -
Get ServletContext in Wicket
ServletContext is useful to provide web information, show you how to get it in Wicket. -
Change Wicket to deployment mode
Two ways to change Wicket from development mode to deployment mode. -
Call Javscript after AJAX update
Show you how to run a Javascript code after ajax updated. -
FileUpload validator is ignored
If no file is selected, FileUpload validator will not execute! solution. -
Configure 404 error page in Wicket
How to configure a 404 error page for not found url. -
Get root context of web application
Common way to get root context of your Wicket project. -
Detect if browser supports JavaScript or Ajax
Wicket way to detect if browser supports JavaScript or Ajax -
Add attribute to a HTML tag dynamically
Example to manipulate attribute in a HTML tag dynamically. -
AjaxLazyLoadPanel in Wicket
Example to use AjaxLazyLoadPanel to enable the lazy load effect.
Common Errors
Some common error messages in Wicket.
- java.lang.ClassNotFoundException : org.slf4j.impl.StaticLoggerBinder
- Enable debug messages for org.apache.wicket.util.resource
Wicket References
- Apache Wicket official website
- Apache Wicket examples
- Apache Wicket Wiki documtation
- Apache Wicket APIs JavaDocs
What’s Next?
To study more topics on Wicket frameworks, I recommend below two great Wicket books.
Hi, i am new to the wicket and i want to add two tabbed panes in one class and call them in the template page. i want to show this panels in the same screen in wicket. can you help me in this problem thanks in advance
Hi, I am newbie to Wicket. Can you please do a tutorial on Tree structures.
Best if can be done on a Panel, So its easy to reuse.
Thanks,
Hi,
I am working on the web application that was developed in Java 1.8, Apache wicket 1.5.6 with embedded jetty server 8.1.16 and also developed few pages using Ext JS 3.4.1. Apache 2.4 has configured as reverse proxy for this application.
The problem is after enabling 2 factor authentication(2FA) and trying to upload more than 2 GB file, apache(proxy) server throws exception as Re-negotiation handshake failed, referer:https:///ui/v2FJNs4Lej0jKivA6KUhqg/v2Fd9/Ns48e request body exceeds maximum size (2147483647) for SSL buffer, referer: https:///ui/DXOKJCEAASQaiEwUH_0xOA/DXO6a/ADXe4
Multipart option is enabled for file uploading
httpd.conf:
#Proxy ui to jetty
I am trying with wicket filter to block the request and update Content-Length to 0 before reaching the proxy server. But request is hitting proxy server first and then come to filter. It did not work.
Anybody was facing similar issue?. I may be doing wrong approach. Please help me out to resolve this issue.
I can provide more detail if still requires.
Can someone suggest my popup in wicket model is not coming in center bu down’
Hello Mkyong, Can you please help me, i need some documentation or examples related to Apache Wicket Forms where I can navigate between a flow of screens having Text fields, Drop downs, Back and Next button.
I tried a simple example with two screens where i can navigate between the two screens. The issue that i am facing is, I am unable to see the form data that i entered in the first screen on click of “Back” button from my second page and also I am not able to see the data that i entered in second screen on clicking “Next” button from 1st screen.
Love your work! Thanks for the Wicket tutorials.
Have a quick question (very new to Wicket)…I have a web page class which extends a master template which, in turn extends WebPage
I need to call a method in an external library & update value of a label. Is onConfigure() the best place call. Doesn’t seem to be working for me.
public class Processed extends Master{
String loginID = “”;
String tmp = “”;
public Processed(PageParameters pageParams) {
super (pageParams);
loginID = pageParams.getString(“userid”);
add(new Label (“result”, “User id = “” + loginID + “”, Key = ” + tmp ));
}
protected void onConfigure() {
KeyUtils kUtils = new KeyUtils();
tmp = kUtils.doMagic(loginID);
}
}
Help would be appreciated. Thanks.
Just a comment on how easy, or otherwise, it is to learn Wicket. If you approach Wicket from the perspective of a Spring MVC, JSF, JSP perspective, it is indeed very different.
However, the difference is that the concept is actually much simpler. Wicket attempts to enfore separation of concerns, therefore (almost) no logic whatsoever in the HTML template. This makes the HTML much more readable, especially from the point of view of a Web Designer. The logic is held within the associated Java class, which could be viewed as the ‘Controller’.
The design of a Wicket application resembles very closely that of a Swing/AWT application, with the added benefit of most of the code for view components not required, as the HTML/CSS takes care of this. Each component can have a ‘model’ object that is automatically updated upon form submit (or value changed) without the need to write any Javascript.
For someone approaching Wicket from a classic Swing Desktop application, it is actually very easy to pick up the concepts behind Wicket. Many of the Widgets even have almost the same name, with the initial letter ‘J’ removed, e.g. TextField instead of JTextField.
Give it a try, you’ll be surprised at how productive you can be in a short period of time.
Hi MkYong, I need an example in wicket for showing please wait dialogue during processing a form submit and form should be locked during submit process.
last news from wicket https://twitter.com/apache_wicket
In all honesty this is a wonderful detailed article nonetheless as with every great authors there are a few items that might be labored after. Yet by no means the actual much less it absolutely was intriguing.
Please teach me how to create Menu in wicket
Nice tutorial. Thanks for some easy to use ideas 🙂
I’m stuck with the problem to display a grid of small pictures (used for a picture based captcha). The pictures are loaded randomly from the database. So I have each of them in a byte[] array and no clue how to display them in some kind of table or grid structure.
Any hint would be highly appreciated!
Best Regards
Hajo
Is it possible to do web service composition using wickets??
is it possibleto do web service composition using wickets
It sounds Netbeans has some problems with wicket. despite Netbeans Plug-in for wicket I couldn’t integrate wicket1.4 with spring . I try to solve this problem for more than one week .
In wicket-Srping MVC integration, can you tell me how to pass the control from wicket page to Spring Controller?
I have found that “org.apache.wicket.markup.html.resources” package is not available in the wicket-core library in wicket 1.5.3 plugin for netbeans 7.1.1.
Is there any way to add the package????????
I am using Netbeans 7.1.1 and i have installed Wicket 1.5.3 and I am a beginner. And find wicket easy to learn.
I am having a problem with a package. I used the package org.apache.wicket.markup.html.resources.StyleSheetReference but it is not recognized.