Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3
Panel
borderStylesolid
titleTable of contents
Table of Contents
minLevel2

Date: 27 January 2006<p>2006
Author: David Leangen http://www.leangen.net

...

Rather, what we need is a repeater that refreshes itself each time the page renders. This is exactly what ListView is for!

Panelinfo

When working with a database, it is often a good choice to
use IDataProvider/Dataview repeaters. Such repeaters are
specifically tailored to work with data retrieved from a
database.

However, for the sake of simplicity, in this example we use
the ListView, which is the "simplest" approach.

...

Code Block
  Note: this code has not been tested. It is only intended to show the concepts.
  
  SearchPage extends WebPage
  {
      String criteria;
      List results;
  
      //getters and setters
  
      public SearchPage()
      {
          ListView view = 
              new ListView ( "list", new PropertyModel(this, "results"))
              {
                   protected void populateItem( ListItem item )
                   {
                       String result = (String) item.getModelObject();
                       item.add( new Label( "item", result ) );
                   }
               }
          );
  
          Form form = new SearchForm(....);
          form.add( new TextField( "idtextField", new PropertyModel(this, "criteria" ) );
          form.add
          ( 
              new Button("button")
              {
                  onsubmitpublic void onSubmit()
                  {
                      results = getResultsFromCriteria(criteria);
                  }
              }
          );
          add(form);
      }
  }

The principle is this: every time the page renders, the ListView will populate itself with the inserted List, that also happens to be a page property. Every time the form is submitted (i.e. there is a new request for a search), the List is updated based on the results obtained using the search string.

In other words, all the objects are created once and only once in the Page constructor, but the data is retrieved dynamically upon each Page render.

Panelinfo

For additional discussion on ListView see:
http://thread.gmane.org/gmane.comp.java.wicket.user/7763

...