Working with REAL Java Objects
Tutorial - Apache Wicket: The Fun Web Framework - Part 4
Top 10 Things Every Wicket Programmer Should Know
This is a condensed version of my list of the top ten things that every Wicket programmer should know. For the complete version, see http://wickettraining.com/resources/ten-things-every-wicket-programmer-should-know.html
- Models – Really make sure that you understand models before writing any large application in Wicket.
- Pull, don't push – In general, your components should be able to pull their state rather than having some other component push the state on it. The example below demonstrates what this means and why it's important. The key is that the constructor only runs once, but many things on the page might change state after the constructor is run. If you push your state into components in your constructor, they are out-of-date as soon as another component changes state. The only alternative is that every component must know about all other components that share state – and that's not “the Wicket way”. Your components should be independent and reusable.
- Wicket is a UI framework – Don't write middle tier or persistence code in Wicket.
- Keep markup and code clean and compact – Become familiar with and use the various aspects of Wicket that allow for reusability – panels, markup inheritance, and fragments as examples.
- Match your hierarchies – It won't take you long at all to learn this rule, but the hierarchy of components in your markup (tags with a wicket:id attribute) must match the hierarchy in your Java code.
- Form processing lifecycle – When dealing with forms, it is important to understand the order of operations of the form post processing. If any step in the process fails the onError method of your form and submitting button will be called rather than the onSubmit method (picture below)
- Java nuances – There are two Java nuances that catch many Wicket newcomers off-guard – serialization and the presence of anonymous inner classes. Become more familiar with both.
- Unit testing – Testing your Wicket code is made relatively easy by using WicketTester. Try it out.
- i18n – Internationalization is made very easy with Wicket. Become familiar with things like wicket:message and file naming standards for Wicket's built-in i18n support.
- Where to find help – Wicket code is well documented, so reading JavaDocs is a good start. Wicket examples can be viewed online at GitHub. Additionally, Wicket has one of busiest and most helpful mailing lists of any open source project. For more information on the Wicket mailing lists, see http://wicket.apache.org/help/email.html.
I chose Apache Wicket because other frameworks sucked the fun out of web programming (okay, this is subjective, but I can say that I didn't personally enjoy them). Most of my time seemed to be spent dealing with pushing state around or writing configuration in XML. Every little change required changes in multiple files – many times in XML, Java, and specialized markup files. It was hard to make cohesive reusable components. A few days with Wicket made me see how drastically different it was. I was writing real Java object-oriented code, and easily creating reusable components. I hope that you will give it a few days for your own project or experiment so that you, too can discover how much fun web programming can be.
For more information on Wicket, see http://wickettraining.com/resources
Jeremy Thomerson is a technology enthusiast who loves exploring, learning, and creating new technologies. He has helped numerous companies upgrade their architectures to multi-tier architectures primarily based on the leading Java open source technologies, including Wicket, Spring, Lucene, Hibernate and more. For the past several years, he has owned and operated the leading U.S. company providing Wicket training and consulting services.
This article originally appeared in Java Tech Journal - Java Web Frameworks. You'll find more of that issue here for download.