title: How to refresh Wicket DataTable after submitting the Search button
body: <p>I would like to refresh the Wicket DataTable after submitting the Search button.
  Here is the code:</p>
  
  <pre><code>public class SearchPanel extends Panel {
  
      private static final long serialVersionUID = 1L;
      private SearchService searchService;
  
      public SearchPanel(String id,final SearchService searchService) {
          super(id);
          this.searchService = searchService;
          add(new SearchForm("searchForm"));
      }
  
      private class SearchForm extends Form {
  
          private static final long serialVersionUID = 1L;
          private String searchString;
  
          public SearchForm(String id) {
              super(id);
              add(new TextField("searchString", new PropertyModel(this, "searchString")));
          }
  
          public void onSubmit() {
              PageParameters params = new PageParameters();
              searchService.findByTitleProperty(params.get("searchString").toString());
          }
  
          public String getSearchString() {
              return searchString;
          }
  
          public void setSearchString(String searchString) {
              this.searchString = searchString;
          }
      }
  }
  </code></pre>
  
  <p>And my "Home Page" is the following:</p>
  
  <pre><code>public class BooksTablePage extends WebPage implements SearchService {
  
      private static final long serialVersionUID = 1L;
      @SpringBean
      private BookService service;
      private List&lt;IColumn&lt;BookDto, String&gt;&gt; columns;
      private SortableBookDtoDataProvider sortableBookDtoDataProvider;
      private DataTable table;
  
      public BooksTablePage() {
  
          add(new SearchPanel("searchPanel",this));
  
          columns = new ArrayList&lt;IColumn&lt;BookDto, String&gt;&gt;();
  
          columns.add(new PropertyColumn(new Model&lt;String&gt;("ID"), "id"));
          columns.add(new PropertyColumn(new Model&lt;String&gt;("ISBN"), "isbn"));
          columns.add(new PropertyColumn(new Model&lt;String&gt;("TITLE"), "title"));
          columns.add(new PropertyColumn(new Model&lt;String&gt;("AUTHOR"), "author",
              "author"));
          columns.add(new PropertyColumn(new Model&lt;String&gt;("COPIES"), "copies",
              "copies"));
  
          //sortableBookDtoDataProvider = new SortableBookDtoDataProvider(service,"Brave");
          sortableBookDtoDataProvider = new SortableBookDtoDataProvider(service);
          table = new DataTable("datatable", columns, sortableBookDtoDataProvider, 3);
          table.addTopToolbar(new HeadersToolbar(table, (ISortStateLocator) table.getDataProvider()));
          add(table);
  
      }
  
      @Override
      public void findByTitleProperty(String value) {
          System.out.println("Search string: "+value);
          sortableBookDtoDataProvider = new SortableBookDtoDataProvider(service,value);
          table = new DataTable("datatable", columns, sortableBookDtoDataProvider, 3);
          table.addTopToolbar(new HeadersToolbar(table, (ISortStateLocator) table.getDataProvider()));
          this.replace(table);
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The SearchService is the following:</p>
  
  <pre><code>public interface SearchService {
  
      public void findByTitleProperty(String value);
  
  }
  </code></pre>
  
  <p>This is the BooksTablePage.html</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;html xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.3-strict.dtd"&gt;
  
  &lt;head&gt;
    &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
    &lt;title&gt;Wicket Library Application&lt;/title&gt;
    &lt;link rel="stylesheet" href="style.css" type="text/css" media="screen" title="Stylesheet" /&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
    &lt;span wicket:id="searchPanel"&gt;&lt;/span&gt;
    &lt;table wicket:id="datatable"&gt;&lt;/table&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>And the SortableBookDtoDataProvider:</p>
  
  <pre><code>public class SortableBookDtoDataProvider extends SortableDataProvider&lt;BookDto, String&gt; {
  
      private static final long serialVersionUID = 1L;
  
      private static List&lt;BookDto&gt; list = new ArrayList&lt;BookDto&gt;();
  
      private SortableBookDtoDataProviderComparator comparator = new SortableBookDtoDataProviderComparator();
  
      public SortableBookDtoDataProvider(BookService service) {
          list.addAll(service.findAll());
          setSort("author", SortOrder.ASCENDING);
      }
  
      public SortableBookDtoDataProvider(BookService service,String title) {
          list.addAll(service.findByTitle(title));
          setSort("author", SortOrder.ASCENDING);
      }
  
      @Override
      public Iterator&lt;BookDto&gt; iterator(long first, long count) {
          List&lt;BookDto&gt; newList = new ArrayList&lt;BookDto&gt;(list);
          Collections.sort(newList, comparator);
          return newList.subList(safeLongToInt(first), safeLongToInt(first + count)).iterator();
      }
  
      @Override
      public long size() {
          return list.size();
      }
  
      @Override
      public IModel&lt;BookDto&gt; model(final BookDto object) {
          return Model.of(object);
      }
  
      @Override
      public void setSort(String property, SortOrder order) {
          super.setSort(property, order);
      }
  
      public int safeLongToInt(long l) {
          if (l &lt; Integer.MIN_VALUE || l &gt; Integer.MAX_VALUE) {
              throw new IllegalArgumentException
                  (l + " cannot be cast to int without changing its value.");
          }
          return (int) l;
      }
  
      class SortableBookDtoDataProviderComparator implements Comparator&lt;BookDto&gt;, Serializable {
          public int compare(final BookDto b1, final BookDto b2) {
              PropertyModel&lt;Comparable&gt; model1 = new PropertyModel&lt;Comparable&gt;(
                  b1, getSort().getProperty());
              PropertyModel&lt;Comparable&gt; model2 = new PropertyModel&lt;Comparable&gt;(
                  b2, getSort().getProperty());
  
              int result = model1.getObject().compareTo(model2.getObject());
  
              if (!getSort().isAscending()) {
                  result = -result;
              }
  
              return result;
          }
      }
  }
  </code></pre>