|
Page Edited :
WICKET :
Reading from a Database
Reading from a Database has been edited by Adam A. Koch (Sep 26, 2007). Content:Table of contents Date: 27 January 2006 OverviewThis article shows how to display read-only information from a database. The text is based mostly on information provided on the mailing list by Igor Vaynberg. Use CaseWe want to search a CRM database for contacts. Contacts are provided based on search criteria. In this application, contact information is read-only. Wicket SolutionThe page that we create will contain a repeater of some kind (see also repeater examples Rather, what we need is a repeater that refreshes itself each time the page renders. This is exactly what ListView is for!
Upon each page render, ListView reads a List (which just happens to be its model object) and renders its list items based on that List. The following is a very basic example of how to go about this. 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(); add( new Label( "item", result ) ); } }; Form form = new SearchForm(....); form.add( new TextField( "id", new PropertyModel(this, "criteria" ) ); form.add ( new Button("button") { public void onSubmit() { results = getResultsFromCriteria(criteria); } } ); } }
ListView vs DataProviderDataProvider is made for working with large data sets where it is too expensive to load the enire dataset into memory at once. DataProvider allows you to only retrieve the window of the dataset you are going to display. If you have a list of 40 items and it is not expensive to load it you might as well use a ListView . [From a post of Igor's to the Wicket-user list - Gwyn |
Unsubscribe or edit your notifications preferences
