Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3
Code Block
class MyPage extends WebPage {

private String criteria;
//getter/setter for criteria

public MyPage() {
 IModel listModel=new LoadableDetachableModel() {
         Object load() {
             UserService service=...get user service;
              List users=service.findUsersFiltered(criteria);
             return users;
         }
 };
 add(new ListView("users", listModel) {....});

so here we have the listview that will show a list that is filtered on
page's criteria property. now we hookup our dropdownchoice in such a way
that it modifies this property and when the page refreshes so will the
listview because it is using a detachble model.

Code Block
Form form=new Form();
add(form);

List filters=new ArrayList();
filters.add("a");
filters.add("b");

form.add(new DropDownChoice("filter", new PropertyModel(this, "criteria"),
filters) {
wantOnChangeNotification() { return true; });
// here we glue dropdown choice to our criteria property via the property model
}}

and thats it. to overview what we have done:

the listview "pulls" its filter from the criteria property on the page and
uses a detachable model so that it refreshes on every request

dropdown choice puts its selection into the criteria property

so the listview is glued to the dropdown choice by sharing a property