package ch.difty.sipamato.web.pages.paper.list;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import org.apache.wicket.authroles.authorization.strategies.role.annotations.AuthorizeInstantiation;
import org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.filter.FilterForm;
import org.apache.wicket.markup.html.form.FormComponent;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.model.StringResourceModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.wicketstuff.annotation.mount.MountPath;

import ch.difty.sipamato.entity.Paper;
import ch.difty.sipamato.entity.PaperFilter;
import ch.difty.sipamato.web.pages.BasePage;
import ch.difty.sipamato.web.pages.paper.provider.SortablePaperProvider;
import de.agilecoders.wicket.core.markup.html.bootstrap.table.TableBehavior;
import de.agilecoders.wicket.extensions.markup.html.bootstrap.table.BootstrapDefaultDataTable;

@MountPath("list")
@AuthorizeInstantiation({ "ROLE_USER" })
public class PaperListPage extends BasePage {

    private static final long serialVersionUID = 1L;

    private FilterForm<PaperFilter> form;

    public PaperListPage(PageParameters parameters) {
        super(parameters);
    }

    protected void onInitialize() {
        super.onInitialize();

        List<IColumn<Paper, String>> columns = new ArrayList<>();
        columns.add(new PropertyColumn<Paper, String>(new StringResourceModel("column.header.id", this, null), Paper.ID, Paper.ID));
        columns.add(new PropertyColumn<Paper, String>(new StringResourceModel("column.header.publicationYear", this, null), Paper.PUBL_YEAR, Paper.PUBL_YEAR));
        columns.add(new PropertyColumn<Paper, String>(new StringResourceModel("column.header.firstAuthor", this, null), Paper.FIRST_AUTHOR, Paper.FIRST_AUTHOR));
        columns.add(new PropertyColumn<Paper, String>(new StringResourceModel("column.header.title", this, null), Paper.TITLE, Paper.TITLE));

        SortablePaperProvider dataProvider = new SortablePaperProvider();
        columns = new ArrayList<>(columns);

        form = new FilterForm<PaperFilter>("searchForm", dataProvider);
        add(form);

        DataTable<Paper, String> table = new BootstrapDefaultDataTable<>("table", columns, dataProvider, 20);
        table.setOutputMarkupId(true);
        table.add(new TableBehavior().striped().hover());
        form.add(table);

        addFieldAndLabel(new TextField<String>("searchField", PropertyModel.of(dataProvider, "filterState." + PaperFilter.SEARCH_MASK)));
    }

    private void addFieldAndLabel(FormComponent<?> field) {
        addFieldAndLabel(form, field, Optional.empty());
    }

}

@@ -553,65 +553,8 @@
 rm;%0A
-import org.apache.wicket.markup.html.form.FormComponent;%0A
 impo
@@ -1397,16 +1397,49 @@
  form;%0A%0A
+    private PaperFilter filter;%0A%0A
     publ
@@ -1593,16 +1593,229 @@
         
+initDefaultModel();%0A%0A        final SortablePaperProvider dataProvider = new SortablePaperProvider(filter);%0A        form = new FilterForm%3CPaperFilter%3E(%22searchForm%22, dataProvider);%0A        add(form);%0A%0A        final 
 List%3CICo
@@ -2465,220 +2465,8 @@
 ));%0A
-%0A        SortablePaperProvider dataProvider = new SortablePaperProvider();%0A        columns = new ArrayList%3C%3E(columns);%0A%0A        form = new FilterForm%3CPaperFilter%3E(%22searchForm%22, dataProvider);%0A        add(form);%0A%0A
     
@@ -2829,16 +2829,34 @@
 H_MASK))
+, Optional.empty()
 );%0A    %7D
@@ -2878,105 +2878,62 @@
 oid 
-addFieldAndLabel(FormComponent%3C?%3E field) %7B%0A        addFieldAndLabel(form, field, Optional.empty()
+initDefaultModel() %7B%0A        filter = new PaperFilter(
 );%0A 

Use defaultModel for filter in list page