tags:

views:

136

answers:

3

The Wicket examples page for TabbedPanel (link) uses separate, distinct classes for each tab (TabPanel1, TabPanel2 and TabPanel3). Is there a reason to not just use three instances of the same class? If yes, what is it? I'm still fairly new to Wicket, but those classes look identical to me.

EDIT: I ran a simple example, using three objects all of class tabPanel. Each one was set to use a different label, and they did display properly.

EDIT AGAIN: After doing more experimentation and reading the later-posted answers, I realized my first example was too simple. Using one class, the tab title can be different but the logic would still be the same. That wouldn't work unless, as someone mentioned, it became a "Swiss Army Knife" class, which is poor design. And that still wouldn't address the markup file.

+1  A: 

If you'd use three instances of the same class, you'd end up with the same content on each tab... Not very usefull is it?

Tim
I don't see why you couldn't set different content in them, though.
Lord Torgamus
Yeah well as your tests show, you could use the same class a few times, but I'm not sure that's a very typical usecase.. Add in some more components and maybe a few form elements, and you'll see reusing the same class isnt that usefull if you want your tabs to be different..
Tim
Okay, clearly I missed something the first time I was reading your answer. I thought you were claiming that you couldn't use three different, say, Strings in one class because they'd all be the same, but I see your point now. If you'll edit your post, I'll undo the -1.
Lord Torgamus
Ah no problem, it's nice to see you came back to mention this.. And granted, my answer wasn't the most detailed one.. msparer does a better job of explaining the issue to someone new to Wicket..
Tim
+2  A: 

Wicket is designed to encourage the development of reusable Components. Consider the three different Classes as different components you'll want to use in different pages of your application with entirely different behaviour and content. Say Tab1 for contact information, Tab2 for a map and Tab3 for pictures. You really wouldn't want to create a Swiss-Army-Knife-Panel to manage all of those different purposes. So different panel-classes are used in the example.

Admittedly the example doesn't use the best values - but it might be a better idea if you start with the general principles of wicket (take special care in learning how working with models works) rather than with these special components from the wicket-extension package.

msparer
A: 

As you have shown it is possible, and would work well where the display of the panel is controlled by the model.

Lets say you had a component that displayed and address, with an embedded google maps image of the location..

You could create 3 instances of the same "AddressWithMapPanel" passing in a different model to each, with each table being the "Home", "Work", "Other" addresses. There you can then use the tab logic to switch between viewing the different addresses, keeping the same UI changes in a central place but getting different content.

stevemac