This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Child pages
  • Filter ListView by criteria from a DropDownChoice
Skip to end of metadata
Go to start of metadata
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.

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

  • No labels