I hope someone can help a newbie who is learning Wicket.
I have the following code which accepts a parameter and then does a database
query to get the 'Data' object. If the user enters the wrong Id the database
query will return null and in this case I want to notify the user the data
could not be found and any other component should be hidden.
But, when I get an null object the code stops working and a null exception
is thrown, any ideas? Or is there a elegant way to do this?
public class DataView extends WebPage {
private Data data;
public DataView(PageParameters parameters) {
long dataId = parameters.getLong("dataId");
DataDao dataDao = new DataDao();
data = dataDao.getData( dataId );
// display message that the data could not be found
Label dataNotFound = new Label("dataNotFound", "Data could not be
found");
dataNotFound.setVisible(data == null);
// otherwise display the panel containing the data
SomePanel panel = new SomePanel("somePanel");
panel.setVisible(data != null);
add(dataNotFound);
add(panel);
}
public class SomePanel extends Panel {
public SomePanel(String id) {
super(id);
// this throws null exception when data is null
Label label = new Label("someLabel", String.valueOf(data.getId()));
add(label);
}
}
}
Thanks