X

Geertjan's Blog

  • April 7, 2006

Wicket has GOT to stop being so cool!

Geertjan Wielenga
Product Manager
Javalobby's R.J. Lorimer is doing Wicket a big favor—he's been breaking down some of Wicket's subtle yet powerful concepts into understandable language, with sample code included. I came across his Wicket: Reusable Panels today, by chance, and modified the spell checker that I've been blogging about in the last few days. Now, the starting page of my application is super simple and clean:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Home Page</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<h2><font color="black">Beginning of Home Page</font></h2><span wicket:id="mainNavigation"/>
<span wicket:id="spellChecker"/>

<h2><font color="black">End of Home Page</font></h2>
</body>
</html>

Note the two lines in bold. Then look at the Java side of the starting page (i.e., each web page in Wicket consists of an HTML file and a Java file):

package wicket.examples.spellchecker;
import wicket.examples.WicketExamplePage;
public class Home extends WicketExamplePage {
/\*\*
\* Creates a new instance of Home
\*/
public Home() {
add(new SpellChecker("spellChecker"));
}
}

And what does this, truly a minimist's nirvana, give me? Well, all of this:

Not bad, right? To make sense of the above screenshot, look at the (hopefully helpful) color coding I added at the start and end of each panel. So, the home page contains two panels—the first is thanks to the Home.java class's extension of WicketExamplePage (consisting of an HTML file and Java file, provided by the Wicket sample distribution and shared among all Wicket samples), while the second is thanks to the instantiation of the SpellChecker panel. And the SpellChecker panel, in turn, consists of an HTML file and a Java file, which I created simply by following R.J. Lorimer's guidelines, in the abovementioned tip, to transform my Wicket Page into a Wicket Panel. Now, wherever I want my spell checker to appear, I can simply add one line in the HTML file and the corresponding one line in the Java file. And that, dear reader, is what it means to create reusable components in the wonderful world of Wicket.

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.