Components for complex pages
Pages and components are real Java objects with encapsulation, inheritance and events. Build a panel once, with its own markup, styles and scripts, and reuse it on every page, or ship a whole component library as a JAR.
| Item | Part | Qty | Ids |
|---|---|---|---|
| 1 | AddressPanel | 2 | billing, shipping |
| 2 | TextField<String> | 4 | street, city in each panel |
public class AddressPanel extends Panel {
public AddressPanel(String id, IModel<Address> address) {
super(id, new CompoundPropertyModel<>(address));
add(new TextField<String>("street"));
add(new TextField<String>("city"));
}
}
// one component, used twice on the same form
form.add(new AddressPanel("billing", billingAddress));
form.add(new AddressPanel("shipping", shippingAddress));