I’m building a Panel called TaskPanel that will display the contents of my
Task class. This simple Panel has a single constructor and a method, that
looks like this:
public class TaskPanel extends Panel {
Task task;
public TaskPanel(String id, final Task task) {
super(id);
add(new Label("name", task.getName()));
add(new Label("description", task.getDescription()));
add(new Label("assignedTo", task.getAssignedTo()));
this.task = task;
}
@Override
protected void onComponentTag(ComponentTag tag) {
if (task.isSelected()) {
// Do something
}
}
}
It seems like I should make Task the model for the Panel, but I'm having
trouble finding information on how to connect them. I imagine it should look
something like this:
public class TaskPanel extends Panel {
public TaskPanel(String id, IModel task) {
super(id, task);
add(new Label("name", ???));
add(new Label("description", ???));
add(new Label("assignedTo", ???));
}
@Override
protected void onComponentTag(ComponentTag tag) {
if (getModel().???.isSelected()) {
// Do something
}
}
}
Am I even heading in the right direction? Is this the right place to be
using a Model, or should I just stick with keeping the Task as an instance
variable in the class?