0

Inside my panel I am adding a listView to a table with a detachable Model:

Edit:

public class TaskDetailsPanel extends Panel {
    ...

  public TaskDetailsPanel(String id, CompoundPropertyModel<LongRunningTask> model) {
    super(id, model);
    Task task = (LongRunningTask) getDefaultModelObject();

    List<Timeframe> testList = task.getTimeframes();

   DetachableTimeframeModel dtm = new DetachableTimeframeModel(new Model<Task>(task));
    ListView frames = new ListView("frame", dtm) {
        @Override
        protected void populateItem(ListItem item) {
            Timeframe tf = (Timeframe) item.getModelObject();
            item.add(new Label("time", "von - bis"));
            item.add(new Label("sentFiles", String.valueOf(tf.getSentFiles())));
            item.add(new Label("receivedFiles", String.valueOf(tf.getReceivedFiles())));
            item.add(new Label("missingMsgIds", String.valueOf(tf.getMissingMsgIds())));
            item.add(new Label("receivedMsgIds", String.valueOf(tf.getReceivedMsgIds())));
        }
    };
        frames.setOutputMarkupId(true);
        add(frames);

       ...
    }
}

Here is my custom detable Model:

class DetachableTimeframeModel extends LoadableDetachableModel {

    LongRunningTask task;

    public DetachableTimeframeModel(LongRunningTask t) {
        task = t;
    }

    @Override
    protected List<Timeframe> load() {
        return task.getTimeframes();
    }
}

When I define a new list List (e.g. ArrayList) inside the panel and add items to it, then it works. But when the list comes from another javabean then it fails.

What am I missing?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
David Sonnenfeld
  • 688
  • 5
  • 17
  • 31

1 Answers1

2

Pass the model containing the longRunningTask to the DetachableTimeframeModel.

In Wicket you should never pull something out of a model just to put it into another model:

class DetachableTimeframeModel extends LoadableDetachableModel {

    IModel<LongRunningTask> task;

    public DetachableTimeframeModel(IModel<LongRunningTask> t) {
        task = t;
    }

    @Override
    protected List<Timeframe> load() {
        return task.getObject().getTimeframes();
    }

    public void detach() {
        super.detach(),

        task.detach();
    }
}

Note that the model passed to TaskDetailsPanel's constructor should be able to load the actual task from somewhere and doesn't just hold a reference to it. Wicket components and models are serialized to the session/page store.

svenmeier
  • 5,681
  • 17
  • 22
  • hmm I did this, but now task.getObject() returns null... and the list size which I get by getTimeFrames() is always 0. But the list size is not 0, I debugged it inside my Counter java class. So seems the detachableModel is not getting the actual task. I did an EDIT in my post, inside the TaskDetailsPanel. I get my task with: Task task = (LongRunningTask) getDefaultModelObject(); and pass it to the DetachableModel like this: DetachableTimeframeModel dtm = new DetachableTimeframeModel(new Model(task)); But still its not working... – David Sonnenfeld Feb 28 '13 at 12:42