1
votes

I am using a LoadableDetachableModel to save some search results in Wicket. For every result such a model is made. This is the code :

    private List<IModel<ResultItem<?>>> results;

    ResultItemModel(ResultItem<?> object, int index) {
        super(object);
        this.index = index;
    }

    @Override
    protected ResultItem<?> load() {
        return results.get(index).getObject();
    }

The constructor gets the object and the index where in the List the item is, so when I do getObject(), it loads the object from the list. But I am receiving a NullPointer when I try to get the objects. Is there something I am missing?

When I debug, I see that the all the correct items are in the list but they later get detached.

Kind regards,

Merlijn

1

1 Answers

0
votes

Well, I fixed it. I surrounded the List with a PropertyModel like this :

resultListModel = new PropertyModel<List<IModel<ResultItem<?>>>>(this,"results");

In the LDM I changed my code to the following :

    @Override
    protected ResultItem<?> load() {
        return resultListModel.getObject().get(index).getObject();
    }

    @Override
    public void detach() {
        resultListModel.setObject(results);
    }