Geertjan's Blog

  • April 6, 2006

Czech Beeer Roks

Geertjan Wielenga
Product Manager
I kind of cheated in yesterday's blog entry because I didn't reveal that I hadn't been able to fully rewrite the NetBeans IDE 5.0 Tutorial for Web Service Clients to a Wicket implementation. The reason was that I didn't really understand how a Wicket ListView works. But, after a few useful pointers from Johan Compagner on the Wicket mailing list, I eventually worked it all out. The problem was that I needed to create ListViews within ListViews, because CDYNE's spell checker web service (discussed in yesterday's blog entry) returns a list containing all the wrong words, so you need to loop within that list to retrieve a single loop of wrong words and within that loop, there's another loop of suggestions per wrong word. So, all that looping, in Wicket, is handled by the ListView, and so I had to remove all my for loops and replace them with the Wicket equivalent.

Here's the snippet that caused the most work (I've added some comments, hopefully they make the code less dense):

listItem.add(new ListView("innerTable1", allwrongwords) {
//Here we populate the list with wrong words
protected void populateItem(ListItem listItem) {
listItem.add(new MultiLineLabel("one_wrong_word", ((Words)allwrongwords.get(listItem.getIndex())).getWord()));
int onewordsuggestioncount = ((Words)allwrongwords.get(listItem.getIndex())).getSuggestionCount();
//Here we populate the list with the number of suggestions
listItem.add(new MultiLineLabel("no_of_suggestions", String.valueOf(onewordsuggestioncount)));
final List allsuggestions = ((Words)allwrongwords.get(listItem.getIndex())).getSuggestions();
listItem.add(new ListView("innerTable2", allsuggestions) {
//Now we populate the list with the suggestions for the given wrong word:
protected void populateItem(ListItem listItem) {
listItem.add(new MultiLineLabel("one_suggestion", ((String)allsuggestions.get(listItem.getIndex()))));

On the HTML side, this is how the above snippet is rendered:

<span wicket:id = "innerTable1">
<ul><li><b><font color="red"><span wicket:id="one_wrong_word">One wrong word goes here</span></font></b>
(<span wicket:id="no_of_suggestions">Number of suggestions goes here</span> suggestions)<br>
<span wicket:id = "innerTable2">
<span wicket:id="one_suggestion">One suggestion goes here</span>

And here's the result (the above snippets relate specifically to the lower part of the screenshot below, where you see the two wrongly spelled words displayed):

This is definitely the most intense bit of work I've done in Wicket and it really was pretty cool. I didn't realize that Wicket's ListViews make for loops superfluous. Never liked them much anyway.

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.