0

I want to create a PageableListView with these arguments:

public PageableListView(final String id, final IModel<? extends List<T>> model

but the second argument final IModel<? extends List<T>> model confuses me abit. I have a list List<Individual> individualList which has some properties I want to use for the PageableListView I'm making. My problem is that I don't know how to cast it, or make it an acceptable argument.

Here is what I was working with:

 List<Individual> individualList = getIndividuals();
 WebMarkupContainer datacontainer = new WebMarkupContainer("data");
 datacontainer.setOutputMarkupId(true);
 add(datacontainer);

PageableListView listview = new PageableListView("rows", individualList, 10) {

        @Override
        protected void populateItem(ListItem item)
        {
            Individual individual = item.getModelObject();
            item.add(new Label("individual_Id", String.valueOf(individual.getId())));
            item.add(new Label("name", individual.getFirstName()));

    };
    datacontainer.add(listview);
    datacontainer.add(new AjaxPagingNavigator("navigator", listview));
    datacontainer.setVersioned(false);

on the line with Individual individual = item.getModelObject(); it gives me error with Type mismatch: cannot convert from Object to IndividualCache.

Lars Karlsen
  • 117
  • 9

1 Answers1

3

PageableListView has a second constructor that just takes a List<T> as an argument:

PageableListView(String id, List<T> list, int itemsPerPage)

See: The JavaDoc

But you are already using that constructor, so there really isn't a problem here. Your problem is that PageableListView<T> is a generic class, but you are using it as a raw type. That's why the method getModelObject will only return an Object.

Don't do that.

Instead use the generic argument to specify what kind of Objects your PageableListView is supposed to display:

 PageableListView<Individual> listview = new PageableListView<Individual>("rows", individualList, 10)
OH GOD SPIDERS
  • 3,091
  • 2
  • 13
  • 16