Table of contents

Simple master-detail example

Working on my Wicket/databinder/Hibernate application I've run into a problem. How I can show master-detail relation entities extracted from the database? No doubt there are tens ways how to do this, but I wanted to exploit mature and convenient Hibernate's lazy loading facility and avoid code cluttering.

Say there is an Order entity list with list of its Items is shown in a master table. Order Items Set is a member, declared with Hibernate @OneToMany annotation, must be shown on neighbour table.

Entity Code
public class Order {
@Id Integer orderId;
@Column Integer number;
Set<OrderItem> items;

public class OrderItem {
@Id Integer itemId;
@Column String itemName;
Markup code
       <table cellspacing="0" cellpadding="2" border="1">
               <tr wicket:id="orders">
                       <td><span wicket:id="orderId">[order id]</span></td>
                       <td><a wicket:id="alink"><span wicket:id="number">[order number]</span></a></td>

       <div wicket:id="itemsWrap"></div>
       <table cellspacing="0" cellpadding="2" border="1">
               <tr wicket:id="items">
                       <td><span wicket:id="itemId">[id]</span></td>
                       <td><span wicket:id="itemName">[name]</span></td>

Clicking on the link 'order number', left panel should be refreshed with the associated list of the order's item list. Of course it is a good idea to use an ajax-based refresh and Wicket good deal with such cases.

To be ended later...

  • No labels