"ExamplePanel.java"
public class ExamplePanel extends Panel {
//declared a boolean variable and setted it to false
boolean isListEmpty = false;
/*
* constructor here
*/
public ExamplePanel(String id) {
super(id);
/*
* getting the list of Strings by executing a sql query under getList() method of "ExamplePanelDAO.java".
* Just suppose that in getList() method a sql query executes and it returns a list of some String object.
*/
final List<String> list = new ExamplePanelDAO().getList();
/*
* Check whether list is empty or not. If it is empty then set "isListEmpty to true"
*/
if(list.size() == 0)
isListEmpty = true;
/*
* Added a Label here with wicket:id="dataNotFoundLabel". Now the most important thing is that we need to override the "isVisible()" method of Wicket component class.
* Since we setted "isListEmpty" to true if list is empty, so this label will be visible only if "isListEmpty" will be true. Otherwise Label will not be visible.
*/
add(new Label("dataNotFoundLabel","Sorry!! Data Not Available.") {
public boolean isVisible() {
return isListEmpty;
}
});
}
}
Another important thing to remember is that when you write markup for the Label in "ExamplePanel.html" you have to write the markup within "<wicket:enclosure>" tag.
"ExamplePanel.html"
<wicket:panel>
<wicket:enclosure>
<label wicket:id="dataNotFoundLabel"></label>
</wicket:enclosure>
</wicket:panel>