What is the purpose of using a separate class for each tab in Wicket?

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

EDIT: I followed a simple example using three objects of the entire tabPanel class. Each was configured to use a different label and they displayed correctly.

EDIT AGAIN: After doing more experimentation and reading the answers received later, I realized that my first example was too simple. Using one class, the title of the tab might be different, but the logic is still the same. It wouldn't work if, as someone mentioned, it became a "Swiss Army Knife" class that is poorly developed. And it still won't address the markup file.

+2


source to share


3 answers


Wicket is designed to encourage the development of reusable components. Consider the three different Classes as different components that you want to be used on different pages of your application with completely different behaviors and content. Say Tab1 for contact information, Tab2 for a card, and Tab3 for photos. You really wouldn't want to create a swiss army-knife-panel to control all these different targets. This example uses different classes of panels.



Admittedly, the example does not use the best values, but it might be better if you start with the general principles of the wicket (pay special attention to how it works with models ) rather than these special components from the wicket expansion pack.

+2


source


If you use three instances of the same class, you end up with the same content on every tab ... Not very useful?



+1


source


As you have shown, this is possible and will work well when the panel display is driven by the model.

Suppose you have a component that is displayed and addressed, with an embedded image of the Google Maps location.

You can create three instances of the same "AddressWithMapPanel" passing in different models, each of which will be the addresses "Home", "Work", "Others". You can then use tabulation logic to switch between viewing different addresses, keeping the same UI changes in a central location, but getting different content.

0


source







All Articles